Implement undo and redo history.