Fixed undo/redo bugs