       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;

#define THREADS _THREADS_
#define PROX _PROX_

__global__ void step(
  const int n,

    dy = xy[ii+1] - xy[jj+1];
    dd = sqrt(dx*dx + dy*dy);

    if (dd<=0.0f){
      continue;
    }

    linked = true;
    for (int l=0;l<cand_count;l++){
      aa = 2*proximity[l];
