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

  dim3 TwoDimBlock(16,16,1);
  dim3 TwoDimGrid(blocksPerGridX,blocksPerGridY,1);

  int *d_hys;
  cudaMalloc((void**) &d_hys, (size.z*sizeof(float)));
  CUT_CHECK_ERROR("Memory hysteresis image creation failed");


}

__device__ int reduceSum(int tid, int data[], int N, int pow2){

  if (tid<pow2){

    if (tid>=N) data[tid] = 0;

    for(unsigned int s=pow2/2; s>0; s>>=1) {
      if (tid < s){
      data[tid] += data[tid + s];
    }
      __syncthreads();
    }

  }
  return(data[0]);

}


__global__ void kernel_hysteresis_glm3(int *hys_img, int3 size, int *modified, int N, int pow2){

  __shared__ float s_slice[18][18];
  __shared__ int s_modified[256];
  __shared__ int m;

  int block_tid = blockDim.x * threadIdx.y + threadIdx.x;
  int tid = block_tid + (blockIdx.x*blockDim.x*blockDim.y)+(blockIdx.y*blockDim.x*blockDim.y*gridDim.x);
  
  ///pixel index of this thread
  int2 pos;
