Just a quick look at your code, I noticed you're iterating CHAT_FRAMES. Temporary chat windows from whispers and the pet battle log aren't added to that table. Their ID is forced as 11 and above and do not persist between sessions.
You can save pointers to all created chat windows, 1-10 or temporary, by hooking FCF_SetWindowName(frame,name). Here's what I do in my TrueChatFrameHistory addon:
Lua Code:
local CF,cfid={},{}
hooksecurefunc("FCF_SetWindowName",function(frame,name)
local id=frame:GetID()
CF[frame]=id -- main ChatFrame pointers
cfid[id]=frame -- access by id
end)
As for the taints, I'm pretty sure it's this:
Lua Code:
local DefaultSetItemRef = SetItemRef
function SetItemRef(link, ...)
Replacing any of Blizzard's objects is not a good idea.