Fix undo functionality