   ///load center
   s_slice[sliceIdx.y][sliceIdx.x] = hys_img[pixIdx];
 
-  s_modified[tid] = 1;
-  if ((threadIdx.x + threadIdx.y) == 0) m = 0;
-
-  for (i=0;i<blockDim.x*blockDim.y;i++){
+  s_modified[block_tid] = 1;
+
+  do{
+
+    if ((threadIdx.x + threadIdx.y) == 0) m = 0;
 
     if (m){
       //store center
       hys_img[pixIdx] = s_slice[sliceIdx.x][sliceIdx.y];
-   }
+    }
 
     if((!i) || m){
 

  cudaUnbindTexture(hysTexRef);
  CUT_CHECK_ERROR("Memory unbind failed");
  cudaFree(d_hys);
  CUT_CHECK_ERROR("Memory free failed");

  

      }
    }

    while(!reduceSum256(block_tid,s_modified)){

      s_modified[block_tid] = 0;

      if(s_slice[sliceIdx.y][sliceIdx.x] == 128){

