code: function copyHistoryArray(events, newGroup) {
      for (var i = 0, copy = []; i < events.length; ++i) {
        var event = events[i], changes = event.changes, newChanges = [];
        copy.push({changes: newChanges, anchorBefore: event.anchorBefore, headBefore: event.headBefore,
                   anchorAfter: event.anchorAfter, headAfter: event.headAfter});
        for (var j = 0; j < changes.length; ++j) {
          var change = changes[j], m;
          newChanges.push({from: change.from, to: change.to, text: change.text});
          if (newGroup) for (var prop in change) if (m = prop.match(/^spans_(\d+)$/)) {
            if (indexOf(newGroup, Number(m[1])) > -1) {
              lst(newChanges)[prop] = change[prop];
              delete change[prop];
            }
          }
        }
      }
      return copy;
    }
docs: Used both to provide a JSON-safe object in .getHistory, and, when detaching a document, to split the history in two