add undo and redo functionalities