cleaning up the undo function