undo function nearly finished