     __syncthreads();
     if (gid < i_to) {
       unsigned int cluster_id = clustering[gid];
+      if (cluster_id == 0) {
+        cluster_id = gid + 1;
+      }
       unsigned int ref_id = tid+bsize;
       // load reference coordinates for re-use into shared memory
       for (unsigned int j=0; j < n_cols; ++j) {

          float c = smem[ref_id*n_cols+j] - smem[i*n_cols+j];
          dist2 = fma(c, c, dist2);
        }
        if (dist2 <= max_dist2) {
          cluster_id = min(cluster_id, i+offset+1);
        }
      }

        // state trajectory is strictly ordered in distance,
        // thus this will always terminate as ids are always
        // smaller or equal to own id
        while (u > prev_max_state && clustering[u-1] != u) {
          u = clustering[u-1];
        }
      }
