   ///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){
 

      }
    }

    while(!reduceSum(tid,s_modified)){

      s_modified[tid] = 0;

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



}

__device__ int reduceSum256(int tid, int data[]){
// data[] should be a 256 positios array

  if (tid < 128) { data[tid] += data[tid + 128]; }
  __syncthreads();
