refactor undo