diff --git a/src/avalanche/functionObjects/gridfileWrite.C b/src/avalanche/functionObjects/gridfileWrite.C
index f3c6fa83da87b42c57610d01de25787315e3c8f2..13d37dbe161cb0a53c8de52bc47c2e16b6c89ee7 100644
--- a/src/avalanche/functionObjects/gridfileWrite.C
+++ b/src/avalanche/functionObjects/gridfileWrite.C
@@ -126,7 +126,7 @@ bool Foam::functionObjects::gridfileWrite::findNNByCellNeighbors()
             scalar x(this->xllcenter_+i*this->dx_);
             scalar y(this->yllcenter_+j*this->dy_);
 
-            searchIndex = -1;
+            searchIndex = 0;
 
              //start at the cell index of neighboring raster cell, assuming the next is close
             if (i > 0)
@@ -139,10 +139,8 @@ bool Foam::functionObjects::gridfileWrite::findNNByCellNeighbors()
                 if (nearestNeighbor_[i*nrows_+j-1] > -1)
                     searchIndex = nearestNeighbor_[i*nrows_+j-1];
             }
-            if (searchIndex < 0)
-                searchIndex = 0;
 
-            label old_SearchIndex = -1;
+            label old_SearchIndex = -2;
             scalar dmin = pow(c[searchIndex].x()-x,2)+
                           pow(c[searchIndex].y()-y,2);
 
@@ -167,7 +165,7 @@ bool Foam::functionObjects::gridfileWrite::findNNByCellNeighbors()
             //check if the point is within the cell
 
             label checkedSI = checkPointInCellandNeighborsIterativly(searchIndex, faceFaceAddr, x, y, 2);
-            if (checkedSI > 0)
+            if (checkedSI > -1)
             {
                 nearestNeighbor_[gridIndex] = checkedSI;
                 foundNewValues = true;
@@ -279,7 +277,7 @@ void Foam::functionObjects::gridfileWrite::writeField(const areaScalarField& f,
                 raster.vRef()[nrows_-j-1][i] = f[nearestNeighbor_[i*nrows_+j]];
                 if (secondOrderInterpolations_)
                 {
-                    raster.vRef()[nrows_-j-1][i] += gradf[nearestNeighbor_[i*nrows_+j]]&(pointsOnSurface_[i*nrows_+j]);
+                    raster.vRef()[nrows_-j-1][i] += (pointsOnSurface_[i*nrows_+j])&gradf[nearestNeighbor_[i*nrows_+j]];
                 }
             }
         }