fix undo function