Add nearly complete support for undo and history