implemented undo and redo methods.