Implemented the undo/redo functions