Index: src/boundary.cpp
===================================================================
--- src/boundary.cpp	(revision f71497989750680f5dd0615f305121f4c4601d64)
+++ src/boundary.cpp	(revision caf5d608169807a028a2cd63e1c2eb8962eaa347)
@@ -1018,14 +1018,76 @@
 };
 
-
-
-
-
-
-//====================================================================================================================
-//
-// ab hier habe ich das verzapft.
-//
-//====================================================================================================================
+void Tesselation::AddTrianglePoint(atom* Candidate, int n)
+{
+	  PointTestPair InsertUnique;
+	  TPS[n] = new class BoundaryPointSet(Candidate);
+	  InsertUnique = PointsOnBoundary.insert( PointPair(Candidate->nr, TPS[n]) );
+	  if (InsertUnique.second)  // if new point was not present before, increase counter
+	  {
+		  PointsOnBoundaryCount++;
+	  }
+	  else
+	  {
+		  delete TPS[n];
+		  cout << Verbose(2) << "Atom " << *((InsertUnique.first)->second->node) << " gibt's schon in der PointMap." << endl;
+		  TPS[n] = (InsertUnique.first)->second;
+	  }
+};
+
+/*
+ * Function tries to add line from current Points in BPS to BoundaryLineSet.
+ * If succesfull it raises the line count and iserts the new line into the BLS, 
+ * if unsuccesfull, it writes the line which had been present into the BLS, deleting the new constructed one.  
+ */
+
+void Tesselation::AddTriangleLine(int n)
+{
+	  LineMap::iterator LineWalker;
+	  BLS[n] = new class BoundaryLineSet(BPS, BPS[1]->node->nr);
+	  if ((BPS[0]->lines.find(BPS[1]->node->nr))->second->endpoints[0] == BLS[n]->endpoints[0]
+	      and (BPS[0]->lines.find(BPS[1]->node->nr))->second->endpoints[1] == BLS[n]->endpoints[1]) 
+		  //If a line is there, how do I recognize that beyond a shadow of a doubt? 
+	  {
+		  delete BLS[n];
+		  cout << Verbose(2) << "Tried to add an existing line, handled it." << endl;
+		  LineWalker = LinesOnBoundary.end();
+		  
+		  while(LineWalker->second->endpoints[0] != BLS[n]->endpoints[0] or LineWalker->second->endpoints[1] != BLS[n]->endpoints[1])
+		  {
+			  cout << Verbose(1) << "Looking for line which already exists"<< endl; 
+			  LineWalker--;
+		  }
+		  BLS[n]=LineWalker->second;
+	  }
+	  else
+	  {
+		  cout << Verbose(2) << "Adding line which has not been used before." << endl;
+		  BPS[1]->lines.insert( LinePair(BPS[0]->node->nr, BLS[n]) );
+		  BPS[2]->lines.insert( LinePair(BPS[1]->node->nr, BLS[n]) );
+		  
+		  LinesOnBoundary.insert( LinePair(LinesOnBoundaryCount, BLS[n]));
+		  LinesOnBoundaryCount++;
+		  
+	  }
+};
+
+/*
+ * Function tries to add Triangle just created to Triangle and remarks if already existent (Failure of algorithm). 
+ * Furthermore it adds the triangle to all of its lines, in order to recognize those which are saturated later.
+ */
+
+void Tesselation::AddTriangleToLines()
+{
+	cout <<Verbose(1) << "Adding triangle to its lines" <<endl;
+	int i=0;
+	TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
+	TrianglesOnBoundaryCount++;
+	for (i=0; i<3; i++)
+	{
+		BLS[i]->AddTriangle(BTS);
+	}
+};
+
+
 
 /*!
@@ -1039,5 +1101,5 @@
  *  with all neighbours of the candidate.
  */
-void Find_next_suitable_point(atom* a, atom* b, atom* Candidate, int n, Vector *Chord, Vector *d1, Vector *OldNormal, atom*& Opt_Candidate, double *Storage, const double RADIUS, molecule* mol, bool problem)
+void Find_next_suitable_point(atom* a, atom* b, atom* Candidate, atom* Parent, int n, Vector *Chord, Vector *d1, Vector *OldNormal, atom*& Opt_Candidate, double *Storage, const double RADIUS, molecule* mol, bool problem)
 {
   /* OldNormal is normal vector on the old triangle
@@ -1108,6 +1170,10 @@
       {
 		  Walker = mol->ListOfBondsPerAtom[Candidate->nr][i]->GetOtherAtom(Candidate);
-
-		  Find_next_suitable_point(a, b, Walker, n+1, Chord, d1, OldNormal, Opt_Candidate, Storage, RADIUS, mol, problem);  //call function again
+		  if (Walker->nr == Parent->nr){
+			  continue;
+		  }
+		  else{
+			  Find_next_suitable_point(a, b, Walker, Candidate, n+1, Chord, d1, OldNormal, Opt_Candidate, Storage, RADIUS, mol, problem);  //call function again
+		  }
       }
   }
@@ -1123,5 +1189,5 @@
   Vector helper;
   Vector Chord;
-  atom* Walker;
+  //atom* Walker;
 
   double Storage[2];
@@ -1156,13 +1222,14 @@
 
   cout << Verbose(1) << "Looking for third point candidates for triangle ... " << endl;
-  Find_next_suitable_point(Line.endpoints[0]->node, Line.endpoints[1]->node, Line.endpoints[0]->node, 0, &Chord, &direction1, &(T.NormalVector), Opt_Candidate, Storage, RADIUS, mol,0);
-
-  if (N>-1)
+  Find_next_suitable_point(Line.endpoints[0]->node, Line.endpoints[1]->node, Line.endpoints[0]->node, Line.endpoints[1]->node, 0, &Chord, &direction1, &(T.NormalVector), Opt_Candidate, Storage, RADIUS, mol,0);
+  Find_next_suitable_point(Line.endpoints[0]->node, Line.endpoints[1]->node, Line.endpoints[1]->node, Line.endpoints[0]->node, 0, &Chord, &direction1, &(T.NormalVector), Opt_Candidate, Storage, RADIUS, mol,0);
+
+  if (N>7)
   {
 	  cout << Verbose(1) << "No new Atom found, triangle construction will crash" << endl;
 	  write_tecplot_file(out, tecplot, this, mol);
 	  tecplot->flush();
-	  Find_next_suitable_point(Line.endpoints[0]->node, Line.endpoints[1]->node, Line.endpoints[0]->node, 0, &Chord, &direction1, &(T.NormalVector), Opt_Candidate, Storage, RADIUS, mol, 1);
-
+	  Find_next_suitable_point(Line.endpoints[0]->node, Line.endpoints[1]->node, Line.endpoints[0]->node, Line.endpoints[1]->node, 0, &Chord, &direction1, &(T.NormalVector), Opt_Candidate, Storage, RADIUS, mol, 1);
+	  Find_next_suitable_point(Line.endpoints[0]->node, Line.endpoints[1]->node, Line.endpoints[1]->node, Line.endpoints[0]->node, 0, &Chord, &direction1, &(T.NormalVector), Opt_Candidate, Storage, RADIUS, mol, 1);
   }
   // Konstruiere nun neues Dreieck am Ende der Liste der Dreiecke
@@ -1170,31 +1237,23 @@
   cout << Verbose(1) << "Adding exactly one Walker for reasons completely unknown to me ... " << endl;
   cout << " Optimal candidate is " << *Opt_Candidate << endl;
-  AddPoint(Opt_Candidate);
-  cout << " Optimal candidate is " << *Opt_Candidate << endl;
-
-  BPS[0] = new class BoundaryPointSet(Opt_Candidate);
-  cout << " Optimal candidate is " << *Opt_Candidate << endl;
-  BPS[1] = new class BoundaryPointSet(Line.endpoints[0]->node);
-  cout << " Optimal candidate is " << *Opt_Candidate << endl;
-  BLS[0] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
-  cout << " Optimal candidate is " << *Opt_Candidate << endl;
-  BPS[0] = new class BoundaryPointSet(Opt_Candidate);
-
-  BPS[1] = new class BoundaryPointSet(Line.endpoints[1]->node);
-  BLS[1] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
-  BLS[2] = new class BoundaryLineSet(Line);
+
+  AddTrianglePoint(Opt_Candidate, 0);
+  AddTrianglePoint(Line.endpoints[0]->node, 1);
+  AddTrianglePoint(Line.endpoints[1]->node, 2);
+  
+  BPS[0] = TPS[0];
+  BPS[1] = TPS[1];
+  AddTriangleLine(0);
+  BPS[0] = TPS[0];
+  BPS[1] = TPS[2];
+  AddTriangleLine(1);
+  BPS[0] = TPS[1];
+  BPS[1] = TPS[2];
+  AddTriangleLine(2);
 
   BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
-  TrianglesOnBoundary.insert( TrianglePair(TrianglesOnBoundaryCount, BTS) );
-  TrianglesOnBoundaryCount++;
-
-  cout << Verbose(1) << "Checking for already present lines ... " << endl;
-  for(int i=0; i<NDIM; i++) // sind Linien bereits vorhanden ???
-  {
-	  if ( (LinesOnBoundary.insert( LinePair(LinesOnBoundaryCount, BTS->lines[i]))).second);
-	  {
-		  LinesOnBoundaryCount++;
-	  }
-  }
+  AddTriangleToLines();
+  
+  
   cout << Verbose(1) << "Constructing normal vector for this triangle ... " << endl;
 
@@ -1210,5 +1269,5 @@
 
 
-void Find_second_point_for_Tesselation(atom* a, atom* Candidate, int n, Vector Oben, atom*& Opt_Candidate, double Storage[2], molecule* mol, double RADIUS)
+void Find_second_point_for_Tesselation(atom* a, atom* Candidate, atom* Parent, int n, Vector Oben, atom*& Opt_Candidate, double Storage[2], molecule* mol, double RADIUS)
 {
 	cout << Verbose(1) << "Looking for second point of starting triangle, recursive level "<< n <<endl;;
@@ -1234,5 +1293,5 @@
 			}
 			else{
-				cout << Verbose(1) << "Supposedly looses to better candidate" << Opt_Candidate->nr << endl;
+				cout << Verbose(1) << "Supposedly looses to a better candidate" << Opt_Candidate->nr << endl;
 			}
 		}
@@ -1244,5 +1303,8 @@
       {
     	  Walker = mol->ListOfBondsPerAtom[Candidate->nr][i]->GetOtherAtom(Candidate);
-    	  Find_second_point_for_Tesselation(a, Walker, n+1, Oben, Opt_Candidate, Storage, mol, RADIUS);
+    	  if (Walker->nr == Parent->nr)
+    		  continue;
+    	  else
+    		  Find_second_point_for_Tesselation(a, Walker, Candidate, n+1, Oben, Opt_Candidate, Storage, mol, RADIUS);
       };
     };
@@ -1306,5 +1368,5 @@
   cout << Verbose(1) << "Number of Bonds: " << mol->NumberOfBondsPerAtom[FirstPoint->nr] << endl;
 
-  Find_second_point_for_Tesselation(FirstPoint, mol->ListOfBondsPerAtom[FirstPoint->nr][0]->GetOtherAtom(FirstPoint), 0, Oben, Opt_Candidate, Storage, mol, RADIUS);
+  Find_second_point_for_Tesselation(FirstPoint, mol->ListOfBondsPerAtom[FirstPoint->nr][0]->GetOtherAtom(FirstPoint), FirstPoint, 0, Oben, Opt_Candidate, Storage, mol, RADIUS);
 
 
@@ -1322,23 +1384,23 @@
 
   cout << Verbose(1) << "Looking for third point candidates \n";
-  Find_next_suitable_point(FirstPoint, SecondPoint, mol->ListOfBondsPerAtom[FirstPoint->nr][0]->GetOtherAtom(FirstPoint), 0, &Chord, &helper, &Oben, Opt_Candidate, Storage, RADIUS, mol, 0);
+  Find_next_suitable_point(FirstPoint, SecondPoint, SecondPoint, FirstPoint, 0, &Chord, &helper, &Oben, Opt_Candidate, Storage, RADIUS, mol, 0);
 
 
   //Starting Triangle is Walker, SecondPoint, Opt_Candidate
 
-  AddPoint(FirstPoint);
-  AddPoint(SecondPoint);
-  AddPoint(Opt_Candidate);
-
-  cout << Verbose(1) << "The found starting triangle consists of " << *FirstPoint << ", " << *SecondPoint << " and " << *Opt_Candidate << "." << endl;
-
-  BPS[0] = new class BoundaryPointSet(FirstPoint);
-  BPS[1] = new class BoundaryPointSet(SecondPoint);
+    cout << Verbose(1) << "The found starting triangle consists of " << *FirstPoint << ", " << *SecondPoint << " and " << *Opt_Candidate << "." << endl;
+
+  AddTrianglePoint(FirstPoint, 0);
+  AddTrianglePoint(SecondPoint, 1);
+  AddTrianglePoint(Opt_Candidate, 2);
+  
+  BPS[0] = TPS[0];
+  BPS[1] = TPS[1];
   BLS[0] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
-  BPS[0] = new class BoundaryPointSet(FirstPoint);
-  BPS[1] = new class BoundaryPointSet(Opt_Candidate);
+  BPS[0] = TPS[1];
+  BPS[1] = TPS[2];
   BLS[1] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
-  BPS[0] = new class BoundaryPointSet(Opt_Candidate);
-  BPS[1] = new class BoundaryPointSet(SecondPoint);
+  BPS[0] = TPS[0];
+  BPS[1] = TPS[2];
   BLS[2] = new class BoundaryLineSet(BPS , LinesOnBoundaryCount);
 
@@ -1366,5 +1428,5 @@
 	int N =0;
 	struct Tesselation *Tess = new Tesselation;
-	cout << Verbose(1) << "Entering finding of non convex hull. " << endl;
+	cout << Verbose(1) << "Entering search for non convex hull. " << endl;
 	cout << flush;
 	const double RADIUS =6.;
Index: src/boundary.hpp
===================================================================
--- src/boundary.hpp	(revision f71497989750680f5dd0615f305121f4c4601d64)
+++ src/boundary.hpp	(revision caf5d608169807a028a2cd63e1c2eb8962eaa347)
@@ -82,4 +82,7 @@
     void GuessStartingTriangle(ofstream *out);
     void AddPoint(atom * Walker);
+    void AddTrianglePoint(atom* Candidate, int n);
+    void AddTriangleLine(int n);
+    void AddTriangleToLines();
     void Find_starting_triangle(molecule* mol, const double RADIUS);
     void Find_next_suitable_triangle(ofstream *out, ofstream *tecplot, molecule* mol, BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, int N);
@@ -88,4 +91,5 @@
     LineMap LinesOnBoundary;
     TriangleMap TrianglesOnBoundary;
+    class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions 
     class BoundaryPointSet *BPS[2];
     class BoundaryLineSet *BLS[3];
Index: src/molecules.cpp
===================================================================
--- src/molecules.cpp	(revision f71497989750680f5dd0615f305121f4c4601d64)
+++ src/molecules.cpp	(revision caf5d608169807a028a2cd63e1c2eb8962eaa347)
@@ -1518,6 +1518,7 @@
 {
   atom *walker = NULL;
-  int No = 0;
+  int AtomNo = 0, ElementNo;
   time_t now;
+  element *runner = NULL;
 
   now = time((time_t *)NULL);   // Get the system time and put it into 'now' as 'calender time'
@@ -1525,12 +1526,22 @@
   while (walker->next != end) { // go through every atom and count
     walker = walker->next;
-    No++;
+    AtomNo++;
   }
   if (out != NULL) {
-    *out << No << "\n\tCreated by molecuilder on " << ctime(&now);
-    walker = start;
-    while (walker->next != end) { // go through every atom of this element
-      walker = walker->next;
-      walker->OutputXYZLine(out);
+    *out << AtomNo << "\n\tCreated by molecuilder on " << ctime(&now);
+    ElementNo = 0;
+    runner = elemente->start;
+    while (runner->next != elemente->end) { // go through every element
+  		runner = runner->next;
+      if (ElementsInMolecule[runner->Z]) { // if this element got atoms
+        ElementNo++;
+        walker = start;
+        while (walker->next != end) { // go through every atom of this element
+          walker = walker->next;
+          if (walker->type == runner) { // if this atom fits to element
+            walker->OutputXYZLine(out);
+          }
+        }
+      }
     }
     return true;
@@ -1716,5 +1727,5 @@
 	        	};
 	        	AddBond(Walker, OtherWalker); //Add the bond between the two atoms with respective indices.
-	        	BondCount++; //Increase bond count of molecule
+	        	
 	        }
 
