Undo function

Undo function implimented correctly.