 
     float v = val;
 
-    int3 n = make_int3( x+1, y+1, level ); // nj ni ns
-
-    int32_t iter;
+    int3 n = make_int3( x, y, level ); // nj ni ns
+
+    int32_t iter = 0;
 
 #define MAX_ITERATIONS 5
 
     /* must be execute at least once */
-    for( iter = 0; iter < MAX_ITERATIONS; iter++) {
+    do {
+        iter++;
+
         // const int z = level - 1;
         /* compute gradient */
         const float x2y1z1 = tex2DLayered<float>( dog, n.x+1, n.y  , n.z   );

    ec.ypos    = yn;
    ec.sigma   = d_sigma0 * pow(d_sigma_k, sn); // * 2;
        // const float sigma_k = powf(2.0f, 1.0f / levels );
#ifdef PRINT_EXTREMA_DEBUG_INFO
    printf("Found an extremum at %d %d (o=%d,l=%d)     -> x:%.1f y:%.1f z:%.1f\n", x+1, y+1, debug_octave, level, xn, yn, sn );
#endif // PRINT_EXTREMA_DEBUG_INFO

    ec.orientation = 0;

    // int32_t y1 = y+1;
    // int32_t y2 = y+2;

    if( sift_mode == Config::OpenCV ) {
        if( x < 5 || y < 5 || x >= width-5 || y >= height-5 ) {
            return false;
        }
    }

    const float val = tex2DLayered<float>( dog, x, y, level );

    ModeFunctions<sift_mode> f;
    if( not f.first_contrast_ok( val ) ) return false;

#if 0
    if( debug_octave==0 && level==2 && x==14 && y==73 ) {
        printf("I am being tested\n");
        printf("thresh = %0.8f\n", floorf( d_threshold ) );
        printf("layer0 = %0.3f %0.3f %0.3f\n"
               "         %0.3f %0.3f %0.3f\n"
               "         %0.3f %0.3f %0.3f\n",
            tex2DLayered<float>( dog, x-1, y-1, level-1 ),
            tex2DLayered<float>( dog, x  , y-1, level-1 ),
            tex2DLayered<float>( dog, x+1, y-1, level-1 ),
            tex2DLayered<float>( dog, x-1, y  , level-1 ),
            tex2DLayered<float>( dog, x  , y  , level-1 ),
            tex2DLayered<float>( dog, x+1, y  , level-1 ),
            tex2DLayered<float>( dog, x-1, y+1, level-1 ),
            tex2DLayered<float>( dog, x  , y+1, level-1 ),
            tex2DLayered<float>( dog, x+1, y+1, level-1 ) );
        printf("layer1 = %0.3f %0.3f %0.3f\n"
               "         %0.3f %0.3f %0.3f\n"
               "         %0.3f %0.3f %0.3f\n",
            tex2DLayered<float>( dog, x-1, y-1, level ),
            tex2DLayered<float>( dog, x  , y-1, level ),
            tex2DLayered<float>( dog, x+1, y-1, level ),
            tex2DLayered<float>( dog, x-1, y  , level ),
            tex2DLayered<float>( dog, x  , y  , level ),
            tex2DLayered<float>( dog, x+1, y  , level ),
            tex2DLayered<float>( dog, x-1, y+1, level ),
            tex2DLayered<float>( dog, x  , y+1, level ),
            tex2DLayered<float>( dog, x+1, y+1, level ) );
        printf("layer2 = %0.3f %0.3f %0.3f\n"
               "         %0.3f %0.3f %0.3f\n"
               "         %0.3f %0.3f %0.3f\n",
            tex2DLayered<float>( dog, x-1, y-1, level+1 ),
            tex2DLayered<float>( dog, x  , y-1, level+1 ),
            tex2DLayered<float>( dog, x+1, y-1, level+1 ),
            tex2DLayered<float>( dog, x-1, y  , level+1 ),
            tex2DLayered<float>( dog, x  , y  , level+1 ),
            tex2DLayered<float>( dog, x+1, y  , level+1 ),
            tex2DLayered<float>( dog, x-1, y+1, level+1 ),
            tex2DLayered<float>( dog, x  , y+1, level+1 ),
            tex2DLayered<float>( dog, x+1, y+1, level+1 ) );
    }
#endif
    if( not is_extremum( dog, x-1, y-1, level-1 ) ) {
        // if( debug_octave==0 && level==2 && x==14 && y==73 ) printf("But I fail\n");
        return false;
    }

