Implemented undo function.