       zk = a*nz+b;
       for (int k=0;k<zone_num[zk];k++){
         jj = 2*zone_node[zk*zone_leap+k];
-        total_count += 1;
-        dx = xy[ii] - xy[jj];
-        dy = xy[ii+1] - xy[jj+1];
-        dd = sqrt(dx*dx + dy*dy);
+        dd = dist(xy, xy, ii, jj);
         if (dd<outer_influence_rad && dd>0.0f){
           proximity[cand_count] = jj/2;
           cand_count += 1;


  int link_count = 0;
  int cand_count = 0;
  int total_count = 0;

  bool linked;


        linked = false;
        break;
      }
      if (dd>max(dist(xy, xy, aa, ii), dist(xy, xy, jj, aa))){
        linked = false;
        break;
      }
    }

    dx /= dd;
    dy /= dd;

    mx += xy[jj];
    my += xy[jj+1];

    if (linked){
      links[10*i+link_count] = jj/2;
      link_count += 1;
      if (dd>spring_attract_rad){
        sx += -dx*spring_stp;
        sy += -dy*spring_stp;
      }
      else if(dd<spring_reject_rad){
        sx += dx*spring_stp;
        sy += dy*spring_stp;
      }
    }
    else{ // unlinked
      sx += dx*reject_stp;
      sy += dy*reject_stp;
    }
  }

