Index: src/Actions/AnalysisAction/DipoleAngularCorrelationAction.cpp
===================================================================
--- src/Actions/AnalysisAction/DipoleAngularCorrelationAction.cpp	(revision caa30bb728eba9087798caddea7ae014d9ba4f4f)
+++ src/Actions/AnalysisAction/DipoleAngularCorrelationAction.cpp	(revision b25fa374bf59ffcdade5ca861bcb1d97d99159cc)
@@ -61,7 +61,7 @@
   ASSERT(!params.periodic, "AnalysisDipoleAngularCorrelationAction() - periodic case not implemented.");
   correlationmap = DipoleAngularCorrelation(molecules);
-  OutputDipoleAngularCorrelation(&output, correlationmap);
+  OutputCorrelationMap<DipoleAngularCorrelationMap>(&output, correlationmap, OutputDipoleAngularCorrelation_Header, OutputDipoleAngularCorrelation_Value);
   binmap = BinData( correlationmap, params.BinWidth, params.BinStart, params.BinEnd );
-  OutputCorrelation ( &binoutput, binmap );
+  OutputCorrelationMap<BinPairMap> ( &binoutput, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
   delete(binmap);
   delete(correlationmap);
Index: src/Actions/AnalysisAction/PairCorrelationAction.cpp
===================================================================
--- src/Actions/AnalysisAction/PairCorrelationAction.cpp	(revision caa30bb728eba9087798caddea7ae014d9ba4f4f)
+++ src/Actions/AnalysisAction/PairCorrelationAction.cpp	(revision b25fa374bf59ffcdade5ca861bcb1d97d99159cc)
@@ -62,7 +62,7 @@
   else
     correlationmap = PairCorrelation(molecules, params.elements);
-  OutputPairCorrelation(&output, correlationmap);
+  OutputCorrelationMap<PairCorrelationMap>(&output, correlationmap, OutputPairCorrelation_Header, OutputPairCorrelation_Value);
   binmap = BinData( correlationmap, params.BinWidth, params.BinStart, params.BinEnd );
-  OutputCorrelation ( &binoutput, binmap );
+  OutputCorrelationMap<BinPairMap> ( &binoutput, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
   delete(binmap);
   delete(correlationmap);
Index: src/Actions/AnalysisAction/PointCorrelationAction.cpp
===================================================================
--- src/Actions/AnalysisAction/PointCorrelationAction.cpp	(revision caa30bb728eba9087798caddea7ae014d9ba4f4f)
+++ src/Actions/AnalysisAction/PointCorrelationAction.cpp	(revision b25fa374bf59ffcdade5ca861bcb1d97d99159cc)
@@ -67,7 +67,7 @@
   else
     correlationmap = CorrelationToPoint(molecules, params.elements, &params.Point);
-  OutputCorrelationToPoint(&output, correlationmap);
+  OutputCorrelationMap<CorrelationToPointMap>(&output, correlationmap, OutputCorrelationToPoint_Header, OutputCorrelationToPoint_Value);
   binmap = BinData( correlationmap, params.BinWidth, params.BinStart, params.BinEnd );
-  OutputCorrelation ( &binoutput, binmap );
+  OutputCorrelationMap<BinPairMap> ( &binoutput, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
   delete(binmap);
   delete(correlationmap);
Index: src/Actions/AnalysisAction/SurfaceCorrelationAction.cpp
===================================================================
--- src/Actions/AnalysisAction/SurfaceCorrelationAction.cpp	(revision caa30bb728eba9087798caddea7ae014d9ba4f4f)
+++ src/Actions/AnalysisAction/SurfaceCorrelationAction.cpp	(revision b25fa374bf59ffcdade5ca861bcb1d97d99159cc)
@@ -81,5 +81,5 @@
     surfacemap = CorrelationToSurface( molecules, params.elements, TesselStruct, LCList);
   delete LCList;
-  OutputCorrelationToSurface(&output, surfacemap);
+  OutputCorrelationMap<CorrelationToSurfaceMap>(&output, surfacemap, OutputCorrelationToSurface_Header, OutputCorrelationToSurface_Value);
   // check whether radius was appropriate
   {
@@ -90,5 +90,5 @@
   }
   binmap = BinData( surfacemap, params.BinWidth, params.BinStart, params.BinEnd );
-  OutputCorrelation ( &binoutput, binmap );
+  OutputCorrelationMap<BinPairMap> ( &binoutput, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
   delete TesselStruct;  // surfacemap contains refs to triangles! delete here, not earlier!
   delete(binmap);
Index: src/analysis_correlation.cpp
===================================================================
--- src/analysis_correlation.cpp	(revision caa30bb728eba9087798caddea7ae014d9ba4f4f)
+++ src/analysis_correlation.cpp	(revision b25fa374bf59ffcdade5ca861bcb1d97d99159cc)
@@ -108,11 +108,12 @@
   outmap = new DipoleAngularCorrelationMap;
   for (std::vector<molecule *>::const_iterator MolWalker = molecules.begin();
-      MolWalker != molecules.end();) {
+      MolWalker != molecules.end(); ++MolWalker) {
     DoLog(2) && (Log()<< Verbose(2) << "Current molecule is "
         << (*MolWalker)->getId() << "." << endl);
     const Vector Dipole = getDipole((*MolWalker)->begin(), (*MolWalker)->end());
-    for (std::vector<molecule *>::const_iterator MolOtherWalker = ++MolWalker;
+    std::vector<molecule *>::const_iterator MolOtherWalker = MolWalker;
+    for (++MolOtherWalker;
         MolOtherWalker != molecules.end();
-        MolOtherWalker++) {
+        ++MolOtherWalker) {
       DoLog(2) && (Log() << Verbose(2) << "Current other molecule is "
           << (*MolOtherWalker)->getId() << "." << endl);
@@ -469,5 +470,5 @@
 int GetBin ( const double value, const double BinWidth, const double BinStart )
 {
-  Info FunctionInfo(__func__);
+  //Info FunctionInfo(__func__);
   int bin =(int) (floor((value - BinStart)/BinWidth));
   return (bin);
@@ -475,73 +476,101 @@
 
 
-/** Prints correlation (double, int) pairs to file.
- * \param *file file to write to
- * \param *map map to write
- */
-void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
-{
-  Info FunctionInfo(__func__);
-  *file << "BinStart\tCount" << endl;
-  for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
-    *file << setprecision(8) << runner->first << "\t" << runner->second << endl;
-  }
-};
-
-/** Prints correlation (double, (atom*,atom*) ) pairs to file.
- * \param *file file to write to
- * \param *map map to write
- */
-void OutputDipoleAngularCorrelation( ofstream * const file, const DipoleAngularCorrelationMap * const map )
-{
-  Info FunctionInfo(__func__);
-  *file << "BinStart\tMolecule1\tMolecule2" << endl;
-  for (DipoleAngularCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
-    *file << setprecision(8) << runner->first << "\t" << runner->second.first->getId() << "\t" << runner->second.second->getId() << endl;
-  }
-};
-
-/** Prints correlation (double, (atom*,atom*) ) pairs to file.
- * \param *file file to write to
- * \param *map map to write
- */
-void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
-{
-  Info FunctionInfo(__func__);
-  *file << "BinStart\tAtom1\tAtom2" << endl;
-  for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
-    *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
-  }
-};
-
-/** Prints correlation (double, int) pairs to file.
- * \param *file file to write to
- * \param *map map to write
- */
-void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
-{
-  Info FunctionInfo(__func__);
-  *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
-  for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
-    *file << runner->first;
-    for (int i=0;i<NDIM;i++)
-      *file << "\t" << setprecision(8) << (runner->second.first->at(i) - runner->second.second->at(i));
-    *file << endl;
-  }
-};
-
-/** Prints correlation (double, int) pairs to file.
- * \param *file file to write to
- * \param *map map to write
- */
-void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
-{
-  Info FunctionInfo(__func__);
-  *file << "BinStart\tTriangle" << endl;
-  if (!map->empty())
-    for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
-      *file << setprecision(8) << runner->first << "\t";
-      *file << *(runner->second.first) << "\t";
-      *file << *(runner->second.second) << endl;
-    }
-};
-
+/** Adds header part that is unique to BinPairMap.
+ *
+ * @param file stream to print to
+ */
+void OutputCorrelation_Header( ofstream * const file )
+{
+  *file << "\tCount";
+};
+
+/** Prints values stored in BinPairMap iterator.
+ *
+ * @param file stream to print to
+ * @param runner iterator pointing at values to print
+ */
+void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner )
+{
+  *file << runner->second;
+};
+
+
+/** Adds header part that is unique to DipoleAngularCorrelationMap.
+ *
+ * @param file stream to print to
+ */
+void OutputDipoleAngularCorrelation_Header( ofstream * const file )
+{
+  *file << "\tAtom1\tAtom2";
+};
+
+/** Prints values stored in DipoleAngularCorrelationMap iterator.
+ *
+ * @param file stream to print to
+ * @param runner iterator pointing at values to print
+ */
+void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner )
+{
+  *file << runner->second.first->getId() << "\t" << runner->second.second->getId();
+};
+
+
+/** Adds header part that is unique to PairCorrelationMap.
+ *
+ * @param file stream to print to
+ */
+void OutputPairCorrelation_Header( ofstream * const file )
+{
+  *file << "\tAtom1\tAtom2";
+};
+
+/** Prints values stored in PairCorrelationMap iterator.
+ *
+ * @param file stream to print to
+ * @param runner iterator pointing at values to print
+ */
+void OutputPairCorrelation_Value( ofstream * const file, PairCorrelationMap::const_iterator &runner )
+{
+  *file << *(runner->second.first) << "\t" << *(runner->second.second);
+};
+
+
+/** Adds header part that is unique to CorrelationToPointMap.
+ *
+ * @param file stream to print to
+ */
+void OutputCorrelationToPoint_Header( ofstream * const file )
+{
+  *file << "\tAtom::x[i]-point.x[i]";
+};
+
+/** Prints values stored in CorrelationToPointMap iterator.
+ *
+ * @param file stream to print to
+ * @param runner iterator pointing at values to print
+ */
+void OutputCorrelationToPoint_Value( ofstream * const file, CorrelationToPointMap::const_iterator &runner )
+{
+  for (int i=0;i<NDIM;i++)
+    *file << "\t" << setprecision(8) << (runner->second.first->at(i) - runner->second.second->at(i));
+};
+
+
+/** Adds header part that is unique to CorrelationToSurfaceMap.
+ *
+ * @param file stream to print to
+ */
+void OutputCorrelationToSurface_Header( ofstream * const file )
+{
+  *file << "\tTriangle";
+};
+
+/** Prints values stored in CorrelationToSurfaceMap iterator.
+ *
+ * @param file stream to print to
+ * @param runner iterator pointing at values to print
+ */
+void OutputCorrelationToSurface_Value( ofstream * const file, CorrelationToSurfaceMap::const_iterator &runner )
+{
+  *file << *(runner->second.first) << "\t" << *(runner->second.second);
+};
Index: src/analysis_correlation.hpp
===================================================================
--- src/analysis_correlation.hpp	(revision caa30bb728eba9087798caddea7ae014d9ba4f4f)
+++ src/analysis_correlation.hpp	(revision b25fa374bf59ffcdade5ca861bcb1d97d99159cc)
@@ -19,4 +19,5 @@
 
 #include <cmath>
+#include <iomanip>
 #include <fstream>
 
@@ -28,4 +29,6 @@
 
 #include "atom.hpp"
+#include "CodePatterns/Info.hpp"
+#include "CodePatterns/Log.hpp"
 #include "CodePatterns/Verbose.hpp"
 
@@ -57,10 +60,14 @@
 CorrelationToSurfaceMap *PeriodicCorrelationToSurface(std::vector<molecule *> &molecules, const std::vector<const element *> &elements, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] );
 int GetBin ( const double value, const double BinWidth, const double BinStart );
-void OutputCorrelation( ofstream * const file, const BinPairMap * const map );
-void OutputDipoleAngularCorrelation( ofstream * const file, const DipoleAngularCorrelationMap * const map );
-void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map );
-void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map );
-void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map );
-
+void OutputCorrelation_Header( ofstream * const file );
+void OutputCorrelation_Value( ofstream * const file, BinPairMap::const_iterator &runner );
+void OutputDipoleAngularCorrelation_Header( ofstream * const file );
+void OutputDipoleAngularCorrelation_Value( ofstream * const file, DipoleAngularCorrelationMap::const_iterator &runner );
+void OutputPairCorrelation_Header( ofstream * const file );
+void OutputPairCorrelation_Value( ofstream * const file, PairCorrelationMap::const_iterator &runner );
+void OutputCorrelationToPoint_Header( ofstream * const file );
+void OutputCorrelationToPoint_Value( ofstream * const file, CorrelationToPointMap::const_iterator &runner );
+void OutputCorrelationToSurface_Header( ofstream * const file );
+void OutputCorrelationToSurface_Value( ofstream * const file, CorrelationToSurfaceMap::const_iterator &runner );
 
 /** Searches for lowest and highest value in a given map of doubles.
@@ -143,3 +150,41 @@
 };
 
+/** Prints correlation map of template type to file.
+ * \param *file file to write to
+ * \param *map map to write
+ * \param (*header) pointer to function that adds specific part to header
+ * \param (*value) pointer to function that prints value from given iterator
+ */
+template <typename T>
+void OutputCorrelationMap(
+    ofstream * const file,
+    const T * const map,
+    void (*header)( ofstream * const file),
+    void (*value)( ofstream * const file, typename T::const_iterator &runner)
+    )
+{
+  Info FunctionInfo(__func__);
+  *file << "BinStart\tBinCenter\tBinEnd";
+  header(file);
+  *file << endl;
+  typename T::const_iterator advancer = map->begin();
+  typename T::const_iterator runner = map->begin();
+  if (advancer != map->end())
+    advancer++;
+  for ( ;(advancer != map->end()) && (runner != map->end()); ++advancer, ++runner) {
+    *file << setprecision(8)
+        << runner->first << "\t"
+        << (advancer->first + runner->first)/2. << "\t"
+        << advancer->first << "\t";
+    value(file, runner);
+    *file << endl;
+  }
+  if(runner != map->end()) {
+    *file << setprecision(8) << runner->first << "\t0\t0\t";
+    value(file, runner);
+    *file << endl;
+  }
+};
+
+
 #endif /* ANALYSIS_HPP_ */
Index: src/unittests/AnalysisCorrelationToPointUnitTest.cpp
===================================================================
--- src/unittests/AnalysisCorrelationToPointUnitTest.cpp	(revision caa30bb728eba9087798caddea7ae014d9ba4f4f)
+++ src/unittests/AnalysisCorrelationToPointUnitTest.cpp	(revision b25fa374bf59ffcdade5ca861bcb1d97d99159cc)
@@ -125,5 +125,5 @@
   // put pair correlation into bins and check with no range
   binmap = BinData( pointmap, 0.5, 0., 0. );
-  OutputCorrelation ( (ofstream *)&cout, binmap );
+  OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
   CPPUNIT_ASSERT_EQUAL( (size_t)3, binmap->size() );
   tester = binmap->begin();
@@ -138,5 +138,5 @@
   // ... and check with [0., 2.] range
   binmap = BinData( pointmap, 0.5, 0., 2. );
-  OutputCorrelation ( (ofstream *)&cout, binmap );
+  OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
   CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
   tester = binmap->begin();
Index: src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
===================================================================
--- src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp	(revision caa30bb728eba9087798caddea7ae014d9ba4f4f)
+++ src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp	(revision b25fa374bf59ffcdade5ca861bcb1d97d99159cc)
@@ -183,5 +183,5 @@
   binmap = BinData( surfacemap, 0.5, 0., 0. );
   CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
-  OutputCorrelation ( (ofstream *)&cout, binmap );
+  OutputCorrelationMap<BinPairMap> ( (ofstream *)&cout, binmap, OutputCorrelation_Header, OutputCorrelation_Value );
   tester = binmap->begin();
   CPPUNIT_ASSERT_EQUAL( 0., tester->first );
