Fix three bugs in new undo code