@Override
 public Void beforeCommit(TransactionData data) throws Exception {
   if (active) {
     check(added, "added to", data.assignedLabels());
     check(removed, "removed from", data.removedLabels());
   }
   active = false;
   return null;
 }
  @Override
  protected void doInitializeChanged() {
    assignedLabels = new HashMap<>();
    removedLabels = new HashMap<>();
    deletedNodeLabels = new HashMap<>();

    Map<Long, Node> potentiallyChangedNodes = new HashMap<>();

    for (LabelEntry labelEntry : transactionData.assignedLabels()) {
      Node node = labelEntry.node();

      if (hasBeenCreated(node)) {
        continue;
      }

      if (!assignedLabels.containsKey(node.getId())) {
        assignedLabels.put(node.getId(), new HashSet<Label>());
      }

      assignedLabels.get(node.getId()).add(labelEntry.label());

      potentiallyChangedNodes.put(node.getId(), node);
    }

    for (LabelEntry labelEntry : transactionData.removedLabels()) {
      Node node = labelEntry.node();

      if (hasBeenDeleted(node)) {
        if (!deletedNodeLabels.containsKey(node.getId())) {
          deletedNodeLabels.put(node.getId(), new HashSet<Label>());
        }
        deletedNodeLabels.get(node.getId()).add(labelEntry.label());
        continue;
      }

      if (!removedLabels.containsKey(node.getId())) {
        removedLabels.put(node.getId(), new HashSet<Label>());
      }
      removedLabels.get(node.getId()).add(labelEntry.label());

      potentiallyChangedNodes.put(node.getId(), node);
    }

    for (Long nodeId : assignedLabels.keySet()) {
      registerChange(potentiallyChangedNodes.get(nodeId));
    }

    for (Long nodeId : removedLabels.keySet()) {
      registerChange(potentiallyChangedNodes.get(nodeId));
    }
  }