undo works, except for some edge cases