will apply highlight)
    updateVisualization();

    // No need for highlightLinkedNodes anymore
    // Return the link for chaining
    return newLink;
  }

  // Update the visualization with current nodes and links
  function updateVisualization() {
    // Update links in linksGroup
    link = linksGroup.selectAll("line").data(links, d => `${d.source.id || d.source}-${d.target.id || d.target}`);
    link.exit().remove();
    const linkEnter = link
      .enter().append("line")
      .attr("class", "link"