Undo redo

I would hope for a test that shows that you can move around in the undo/redo stack at will.  The thing with the flags that are never unset makes me wonder whether an undo-redo-undo cycle will return the right state.   I think it will, but I haven't followed the entire logic.