Undo-redo functionality

Uglish(yet), but seems to be working.