Complete undo function