Fixed undo functionality