Actually, I think the mechanism at the beginning is causing flags to move without adding to the undo stack. Then when undoing the values for other objects become flags, and you get a bunch of garbage data.