 	  for (int i = 0; i < num_coords; i++) {
 		  atomicAdd(&new_clusters[new_cluster_idx * num_coords + i], 
             points[i * num_points + obj_idx]);
-  	}
-  }
-
-	__syncthreads();
+	  }
+
+  	__syncthreads();
 
 #ifdef DEVICE_TIMING
 if (tid == 0) {

}
#endif

  if (obj_idx < num_points) {
    int old_cluster_idx = membership[obj_idx];
	  #ifdef SYNCOUNT
  	membership_changes[bid] = __syncthreads_count(old_cluster_idx != new_cluster_idx);

if (tid == 0) { start = clock(); }
#endif

      for (int i = 0; i < s_per_time; i++) {
        if ((dist = dist_square(num_coords, num_points, points, obj_idx, 
              &s_clusters[i * num_coords]))
			  	  	< min_dist) {
				    min_dist = dist;
			  	  new_cluster_idx = i;
	      }
	  	}
    }

    // process the remaining clusters.
    // The final loop is unrolled to avoid an extra comparison in the previous loops
    for (int t = times * s_per_time; t < num_clusters; t ++) {

      for (int i = tid; i < (num_clusters - times * s_per_time) * num_coords; i ++) {
        s_clusters[i] = clusters[times * s_per_time + i];
      }

      __syncthreads();

      for (int i = 0; i < num_clusters - times * s_per_time; i++) {
        if ((dist = dist_square(num_coords, num_points, points, obj_idx, 
              &s_clusters[i * num_coords]))
              < min_dist) {
            min_dist = dist;
            new_cluster_idx = i;
        }
      }
    }

#ifdef DEVICE_TIMING
if (tid == 0) {
