adding undo functionality

Kinda buggy. Need to resolve names.