refactored undo-related stuff