implemented undo function