Pattern for undo code