Implement undo and redo with command pattern