Index: /issm/trunk-jpl/src/wrappers/ExpSimplify/ExpSimplify.cpp
===================================================================
--- /issm/trunk-jpl/src/wrappers/ExpSimplify/ExpSimplify.cpp	(revision 14340)
+++ /issm/trunk-jpl/src/wrappers/ExpSimplify/ExpSimplify.cpp	(revision 14341)
@@ -37,9 +37,9 @@
 
 		/*calculate the shortest distance of all vertices between ind0 and ind1*/
-		for(int i=ind0;i<ind1;i++){
-			distance = sqrt((x[i]-x[i+1])*(x[i]-x[i+1]) + (y[i]-y[i+1])*(y[i]-y[i+1]));
+		for(int i=ind0;i<ind1-1;i++){
+			distance = sqrt((x[ind0]-x[i+1])*(x[ind0]-x[i+1]) + (y[ind0]-y[i+1])*(y[ind0]-y[i+1]));
 			if(i==ind0 || distance>maxdistance){
 				maxdistance=distance;
-				index = i;
+				index = i + 1;
 			}
 		}
@@ -54,6 +54,6 @@
 		 *
 		 * So: beta = <x-x0,xend-x0>/<xend-x0,xend-x0>  */
-		 
-		for(int i=ind0+1;i<ind1;i++){
+
+		for(int i=ind0+1;i<=ind1;i++){
 			beta = ((x[i]-x[ind0])*(x[ind1]-x[ind0]) + (y[i]-y[ind0])*(y[ind1]-y[ind0]))/((x[ind1]-x[ind0])*(x[ind1]-x[ind0])+(y[ind1]-y[ind0])*(y[ind1]-y[ind0]));
 			dx   = x[i]-beta*x[ind1]+(beta-1.)*x[ind0];
@@ -78,4 +78,6 @@
 		 * (index and ind1)*/
 		_assert_(index!=-1);
+		_assert_(index!=ind1);
+		_assert_(index!=ind0);
 		simplify(contour,flags,ind0 ,index,tolerance);
 		simplify(contour,flags,index,ind1, tolerance);
@@ -157,4 +159,5 @@
 			/*Start recursive call to simplify*/
 			for(int i=0;i<nods;i++) flags[i]=true;
+			printf("-------------- file: ExpSimplify.cpp line: %i\n",__LINE__); 
 			simplify(contour,flags,0,nods-1,tolerance);
 		}
