diff --git a/src/Structure/BoundaryGeometry.cpp b/src/Structure/BoundaryGeometry.cpp
index d71f2ffc851696bf4582da0eb4cf04a42fc5f560..78fe8fe88f38f65f418315c83622e81e01a4f101 100644
--- a/src/Structure/BoundaryGeometry.cpp
+++ b/src/Structure/BoundaryGeometry.cpp
@@ -1962,26 +1962,26 @@ Change orientation if diff is:
                   Find next untested triangle, trivial for the first sub-mesh.
                   There is a least one not yet tested triangle!
                 */
-                while (isOriented [triangle_id])
+                while (isOriented[triangle_id])
                     triangle_id++;
 
                 // ensure that normal of this triangle is inward pointing
                 if (!hasInwardPointingNormal (bg, triangle_id)) {
                     std::swap (bg->PointID (triangle_id, 2), bg->PointID (triangle_id, 3));
                 }
-                isOriented [triangle_id] = true;
+                isOriented[triangle_id] = true;
 
                 // loop over all triangles in sub-mesh
-                triangles [queue_end++] = triangle_id;
+                triangles[queue_end++] = triangle_id;
                 do {
-                    for (auto neighbor_id: neighbors [triangle_id]) {
-                        if (isOriented [neighbor_id]) continue;
+                    for (auto neighbor_id: neighbors[triangle_id]) {
+                        if (isOriented[neighbor_id]) continue;
                         orientTriangle (bg, triangle_id, neighbor_id);
-                        isOriented [neighbor_id] = true;
+                        isOriented[neighbor_id] = true;
                         triangles[queue_end++] = neighbor_id;
                     }
-                    triangle_id = triangles [++queue_cursor];
-                } while (queue_cursor < queue_end);
+                    queue_cursor++;
+                } while (queue_cursor < queue_end && (triangle_id = triangles[queue_cursor],true));
             } while (queue_end < bg->Triangles_m.size());
 
             if (parts == 1) {