fixed the undo functionality