Index: src/tesselation.cpp
===================================================================
--- src/tesselation.cpp	(revision a26ca5140652c255825d40c6ec097d98b9ff01c1)
+++ src/tesselation.cpp	(revision 711ac235cedd19a7f06cfb285964b12e50269c03)
@@ -326,6 +326,4 @@
  */
 BoundaryTriangleSet::BoundaryTriangleSet() :
-  top(NULL),
-  AngleFromTop(-1.),
   Nr(-1)
 {
@@ -343,6 +341,4 @@
  */
 BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number) :
-  top(NULL),
-  AngleFromTop(-1.),
   Nr(number)
 {
@@ -397,9 +393,4 @@
   }
   //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl;
-};
-
-void BoundaryTriangleSet::SetTopNode(const BoundaryTriangleSet * const topnode)
-{
-  top = topnode;
 };
 
@@ -2252,6 +2243,9 @@
 
     FindSecondPointForTesselation(BaseLine->endpoints[0]->node, NormalVector, Temporary, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
-    if (Temporary == NULL)  // have we found a second point?
+    if (Temporary == NULL) {
+      // have we found a second point?
+      delete BaseLine;
       continue;
+    }
     BaseLine->endpoints[1] = new BoundaryPointSet(Temporary);
 
@@ -2299,7 +2293,8 @@
     }
 
-    if (BTS != NULL) // we have created one starting triangle
+    if (BTS != NULL) { // we have created one starting triangle
+      delete BaseLine;
       break;
-    else {
+    } else {
       // remove all candidates from the list and then the list itself
       OptCandidates.pointlist.clear();
@@ -2655,5 +2650,5 @@
       // add normal and degenerate triangles
       Log() << Verbose(1) << "Triangle of endpoints " << *TPS[0] << "," << *TPS[1] << " and " << *TPS[2] << " is degenerated, adding both sides." << endl;
-      BoundaryTriangleSet * const triangle = AddDegeneratedTriangle(CandidateLine, RADIUS, LC);
+      AddDegeneratedTriangle(CandidateLine, RADIUS, LC);
     } else {
       // add this triangle
@@ -2676,36 +2671,14 @@
  * \param RADIUS radius of sphere
  * \param *LC pointer to LinkedCell structure
- * \return pointer to created other triangle
- */
-BoundaryTriangleSet * const  Tesselation::AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC)
+ */
+void Tesselation::AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC)
 {
   Info FunctionInfo(__func__);
-  BoundaryTriangleSet *triangle = NULL;
-  pair<LineMap::iterator,LineMap::iterator> FindPair[3];
-  int LineCase[3];
-  int count[3];
   Vector Center;
   CandidateMap::const_iterator CandidateCheck = OpenLines.end();
-
-  /// 1. For each new pair of endpoints, find and count the number of present lines
-  Log() << Verbose(0) << "INFO: Counting present open lines ..." << endl;
-  for (int i=0;i<3;i++) {
-    BLS[i] = NULL;
-    LineCase[i] = -1;
-    // find already present lines
-    FindPair[i] = TPS[(i+0)%3]->lines.equal_range(TPS[(i+1)%3]->Nr);
-    // count their number
-    count[i] = 0;
-    Log() << Verbose(1) << "For line between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;
-    for (LineMap::iterator FindLine = FindPair[i].first; FindLine != FindPair[i].second; FindLine++)
-      if (FindLine->second->triangles.size() == 1) {
-        Log() << Verbose(1) << "  open line " << *FindLine->second << "." << endl;
-        count[i]++;
-      }
-    Log() << Verbose(1) << "  SUM: there are " << count[i] << " line(s) present."  << endl;
-  }
-
-  /// 2. Create or pick the lines for the first triangle
-  // for each count we have a different case:
+  BoundaryTriangleSet *triangle = NULL;
+
+  /// 1. Create or pick the lines for the first triangle
+  // for each amount of open lines we have a different case:
   // case 0: no triangles at this line and not closed
   // case 1: no triangles at new line is closed
@@ -2715,52 +2688,14 @@
   Log() << Verbose(0) << "INFO: Creating/Picking lines for first triangle ..." << endl;
   for (int i=0;i<3;i++) {
+    BLS[i] = NULL;
     Log() << Verbose(0) << "Current line is between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;
-    switch (count[i]) {
-      case 0:
-        AddNewTesselationTriangleLine(TPS[(i+0)%3], TPS[(i+1)%3], i);
-        break;
-      case 1:
-//        // check whether present line has right candidate
-//        CandidateCheck = OpenLines.find(FindPair[i].first->second);
-//        if (CandidateCheck != OpenLines.end()) {
-//          if (!CandidateCheck->second->pointlist.empty()) {
-//            for (TesselPointList::const_iterator Runner = CandidateCheck->second->pointlist.begin(); Runner != CandidateCheck->second->pointlist.end(); ++Runner) {
-//              Log() << Verbose(1) << "Found candidate " << *(*Runner) << " with Candidate center is " << CandidateCheck->second->OptCenter << ", desired opt center is " << CandidateLine.OptCenter << "." << endl;
-//              if (((*Runner) == TPS[(i+2)%3]->node) && (CandidateLine.OptCenter == CandidateCheck->second->OptCenter)) { // seems like we found a line to connect to
-//                AddExistingTesselationTriangleLine(CandidateCheck->first, i);
-//                break;  // have to break as a AddExistingTesselationTriangleLine changes OpenLines
-//              }
-//            }
-//          } else {
-//            Log() << Verbose(1) << "Open line between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << " has no candidate." << endl;
-//          }
-//        } else {
-//          Log() << Verbose(1) << "No open lines present for line between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << "." << endl;
-//        }
-//        if (BLS[i] == NULL) {
-//          AddNewTesselationTriangleLine(TPS[(i+0)%3], TPS[(i+1)%3], i);
-//        }
-        AddTesselationLine(&CandidateLine.OptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
-        break;
-      default:
-      case 2:
-        AddTesselationLine(&CandidateLine.OptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
-        break;
-//        DoeLog(0) && (eLog() << Verbose(0) << "There are more than two BoundaryPointSets between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << "." << endl);
-//        performCriticalExit();
-//        break;
-    }
-  }
-
-  /// 3. create the first triangle and NormalVector and so on
+    AddTesselationLine(&CandidateLine.OptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
+  }
+
+  /// 2. create the first triangle and NormalVector and so on
   Log() << Verbose(0) << "INFO: Adding first triangle with center at " << CandidateLine.OptCenter << " ..." << endl;
   BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
   AddTesselationTriangle();
-  // check whether triangle has been created
-  BTS->SetTopNode(CandidateLine.T);
-  if (CandidateLine.T != NULL)  // start triangle has angle from top of -1
-    BTS->AngleFromTop = CandidateLine.ShortestAngle;
-  else
-    BTS->AngleFromTop = -1.;
+
   // create normal vector
   BTS->GetCenter(&Center);
@@ -2775,5 +2710,5 @@
   triangle = BTS;
 
-  /// 4. Gather candidates for each new line
+  /// 3. Gather candidates for each new line
   Log() << Verbose(0) << "INFO: Adding candidates to new lines ..." << endl;
   for (int i=0;i<3;i++) {
@@ -2787,53 +2722,16 @@
   }
 
-  /// 5. Create or pick the lines for the second triangle
+  /// 4. Create or pick the lines for the second triangle
   Log() << Verbose(0) << "INFO: Creating/Picking lines for second triangle ..." << endl;
   for (int i=0;i<3;i++) {
     Log() << Verbose(0) << "Current line is between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;
-    switch (count[i]) {
-      case 0:
-        AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
-        break;
-      case 1:
-//        // check whether present line has right candidate
-//        CandidateCheck = OpenLines.find(BLS[i]);
-//        BLS[i] = NULL;
-//        if (CandidateCheck == OpenLines.end()) {  // first triangle has closed present line
-//          AddNewTesselationTriangleLine(TPS[(i+0)%3], TPS[(i+1)%3], i);
-//        } else {
-//          for (TesselPointList::const_iterator Runner = CandidateCheck->second->pointlist.begin(); Runner != CandidateCheck->second->pointlist.end(); ++Runner) {
-//            Log() << Verbose(1) << "Found candidate " << *(*Runner) << " with Candidate center is " << CandidateCheck->second->OptCenter << ", desired other opt center is " << CandidateLine.OtherOptCenter << "." << endl;
-//            if (((*Runner) == TPS[(i+2)%3]->node) && (CandidateLine.OtherOptCenter == CandidateCheck->second->OptCenter)) { // seems like we found a line to connect to
-//              AddExistingTesselationTriangleLine(CandidateCheck->first, i);
-//              break;  // have to break as a AddExistingTesselationTriangleLine changes OpenLines
-//            }
-//          }
-//        }
-//        if (BLS[i] == NULL) {
-//          DoeLog(0) && (eLog() << Verbose(0) << "BoundaryLine between " << TPS[(i+0)%3] << " and " << TPS[(i+1)%3] << " has not the correct candidate, i.e. the third endpoint: " << *TPS[(i+2)%3] << endl);
-//          performCriticalExit();
-//        }
-        AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
-        break;
-      case 2:
-      default:
-        AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
-        break;
-//        DoeLog(0) && (eLog() << Verbose(0) << "There are more than two BoundaryPointSets between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << "." << endl);
-//        performCriticalExit();
-//        break;
-    }
-  }
-
-  /// 6. create the second triangle and NormalVector and so on
+    AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i+2)%3], TPS[(i+0)%3], TPS[(i+1)%3], i);
+  }
+
+  /// 5. create the second triangle and NormalVector and so on
   Log() << Verbose(0) << "INFO: Adding second triangle with center at " << CandidateLine.OtherOptCenter << " ..." << endl;
   BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
   AddTesselationTriangle();
-  // check whether triangle has been created
-  BTS->SetTopNode(CandidateLine.T);
-  if (CandidateLine.T != NULL)  // start triangle has angle from top of -1
-    BTS->AngleFromTop = CandidateLine.ShortestAngle;
-  else
-    BTS->AngleFromTop = -1.;
+
   BTS->SphereCenter.CopyVector(&CandidateLine.OtherOptCenter);
   // create normal vector in other direction
@@ -2846,5 +2744,14 @@
     Log() << Verbose(0) << "--> New degenerate starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl;
 
-  return triangle;
+  /// 6. Adding triangle to new lines
+  Log() << Verbose(0) << "INFO: Adding second triangles to new lines ..." << endl;
+  for (int i=0;i<3;i++) {
+    Log() << Verbose(0) << "Current line is between " << *TPS[(i+0)%3] << " and " << *TPS[(i+1)%3] << ":" << endl;
+    CandidateCheck = OpenLines.find(BLS[i]);
+    if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
+      if (CandidateCheck->second->T == NULL)
+        CandidateCheck->second->T = BTS;
+    }
+  }
 };
 
@@ -2866,10 +2773,4 @@
   BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
   AddTesselationTriangle();
-  // store values from tesselation procedure therein
-  BTS->SetTopNode(CandidateLine.T);
-  if (CandidateLine.T != NULL)  // start triangle has angle from top of -1
-    BTS->AngleFromTop = CandidateLine.ShortestAngle;
-  else
-    BTS->AngleFromTop = -1.;
 
   // create normal vector
@@ -5064,4 +4965,5 @@
         }
   }
+  delete(DegeneratedTriangles);
 
   /// 3. Find connected endpoint candidates and put them into a polygon
Index: src/tesselation.hpp
===================================================================
--- src/tesselation.hpp	(revision a26ca5140652c255825d40c6ec097d98b9ff01c1)
+++ src/tesselation.hpp	(revision 711ac235cedd19a7f06cfb285964b12e50269c03)
@@ -163,10 +163,7 @@
     bool IsPresentTupel(const BoundaryPointSet * const Points[3]) const;
     bool IsPresentTupel(const BoundaryTriangleSet * const T) const;
-    void SetTopNode(const BoundaryTriangleSet * const topnode);
 
     class BoundaryPointSet *endpoints[3];
     class BoundaryLineSet *lines[3];
-    const BoundaryTriangleSet *top; //!< triangle was instantiated during tesselation from this triangle
-    double AngleFromTop;
     Vector NormalVector;
     Vector SphereCenter;
@@ -288,5 +285,5 @@
     void AddTesselationTriangle(const int nr);
     void AddCandidateTriangle(CandidateForTesselation &CandidateLine);
-    BoundaryTriangleSet * const AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC);
+    void AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC);
     void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC);
     void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
