 node for chaining
    return newNode;
  }

  // Track highlighted (linked) nodes
  const highlightedNodes = new Set();

  // Link two nodes by their labels
  function linkNodes(fromLabel, toLabel) {
    // Check if both nodes exist
    const fromNode = nodes.find(n => n.id === fromLabel);
    const toNode = nodes.find(n => n.id === toLabel);

    if (!fromNode || !toNode) {
      throw new Error(`Cannot link: one or both nodes don't exist (${fromLabel}, ${toLabel})`);
    }

    // Check if link already ex