 	    }
 	}
       
-      dim3 grid(25, 40, 24);
-      dim3 block(2, 1, 50);
+      dim3 grid(1, 400, 24);
+      dim3 block(1, 7, 50);
 
       spherer.rfactor = 0.005;
       spherer.roffset = -10;
-      spherer.baseoffsetx = NX / 2 - 30 - 0.5;
-      spherer.baseoffsety = NY / 2 - 10 - 0.5;
+      spherer.baseoffsetx = NX / 2 + 70 - 0.5; // good val -10
+      spherer.baseoffsety = NY / 2 + 70 - 0.5; // good val +10
       dPhotons.assign(photonVals.data(), photonVals.data() + NY * NX);
       dLambdas.assign(lambdaVals.data(), lambdaVals.data() + NY * NX);
       

target[idx] = -1e10;
intens[idx] = 0;
}
  likelihood likelihooder(myspherer, intensityfactor);
  float likelihood1 = thrust::reduce(thrust::seq,
				   thrust::make_transform_iterator(thrust::make_counting_iterator(0), likelihooder),
				   thrust::make_transform_iterator(thrust::make_counting_iterator(NY * NX), likelihooder));
  likelihooder.factor = intensityfactor * 1.01;
  float likelihood2 = thrust::reduce(thrust::seq,
				   thrust::make_transform_iterator(thrust::make_counting_iterator(0), likelihooder),
				   thrust::make_transform_iterator(thrust::make_counting_iterator(NY * NX), likelihooder));

  float dir = 1.01;
  if (likelihood2 < likelihood1)
  {
    dir = 0.99;
    likelihooder.factor = intensityfactor;
    likelihood2 = likelihood1;
  }

  int steps = 0;
  do    
  {
    likelihood1 = likelihood2;
    likelihooder.factor *= dir;
    likelihood2 = thrust::reduce(thrust::seq,
				   thrust::make_transform_iterator(thrust::make_counting_iterator(0), likelihooder),
				   thrust::make_transform_iterator(thrust::make_counting_iterator(NY * NX), likelihooder));
    steps++;
  } while (likelihood2 > likelihood1 && steps < 10);

  target[idx] = likelihood1;
  intens[idx] = likelihooder.factor / dir + steps * 1000;
}

int main()

{
  myspherer.r = exp(myspherer.roffset + (threadIdx.z + blockIdx.z * blockDim.z) * myspherer.rfactor);
  myspherer.offsetx = (threadIdx.x + blockIdx.x * blockDim.x) + myspherer.baseoffsetx;
  myspherer.offsety = /*(blockIdx.y +*/ myspherer.baseoffsety/*)*/;
  myspherer.lfactor = 1.0 / sqrt(lsum) * threadIdx.y + 1.0;

  int idx =  (threadIdx.x + blockIdx.x * blockDim.x)  + (threadIdx.y + blockIdx.y * blockDim.y) * gridDim.x * blockDim.x + (threadIdx.z + blockIdx.z * blockDim.z)  * gridDim.x * blockDim.x * gridDim.y * blockDim.y;
