Refactoring for undo/redo