diff --git a/AMDiS/src/ElInfo2d.cc b/AMDiS/src/ElInfo2d.cc
index af832bc1664686b95237e4430419d4150bc3429c..7839cfc43327c7db395b9ba5ac3e1477a2b9ad8c 100644
--- a/AMDiS/src/ElInfo2d.cc
+++ b/AMDiS/src/ElInfo2d.cc
@@ -411,11 +411,6 @@ namespace AMDiS {
 	
 	Element *nb = elInfoOld->neighbour[2];
 	if (nb) {
-// 	  MSG("OLDINFO HAS EL %d mit PTR %p\n", elInfoOld->getElement()->getIndex(),
-// 	      elInfoOld->getElement());
-
-// 	  MSG("1 ALS NACHBAR HABEN WIR %d mit PTR %p\n", nb->getIndex(), nb);
-
 	  TEST_EXIT_DBG(elInfoOld->oppVertex[2] == 2)
 	    ("Fill child %d of element %d (mel %d): Invalid neighbour %d!\n",
 	     ichild,
@@ -429,8 +424,6 @@ namespace AMDiS {
 	    ("Missing second child in element %d!\n", nb->getIndex());
 	 
 	  nb = nb->getSecondChild();
-	  // 	  MSG("2 ALS NACHBAR HABEN WIR %d mit PTR %p (is LEAF: %d)\n", 
-	  //	  nb->getIndex(), nb, nb->isLeaf());
 
 	  if (nb->getFirstChild()) {
 	    oppVertex[0] = 2;
@@ -450,7 +443,6 @@ namespace AMDiS {
 	    }	   
  
 	    nb = nb->getFirstChild();
-	    //	    MSG("3 ALS NACHBAR HABEN WIR %d\n", nb->getIndex());
 	  } else {
 	    oppVertex[0] = 1;
 
diff --git a/AMDiS/src/FiniteElemSpace.cc b/AMDiS/src/FiniteElemSpace.cc
index 096fe5e2ae18ed5c1f336fd1fe05315e27965ef1..631a0ffa03caf5da4c873e0811dce1429fccb5bb 100644
--- a/AMDiS/src/FiniteElemSpace.cc
+++ b/AMDiS/src/FiniteElemSpace.cc
@@ -26,8 +26,10 @@ namespace AMDiS {
     if (!admin) {
       const DOFAdmin *admin_local = NULL;
       const DimVec<int> *ndof = NULL;
+
       ndof = basFcts->getNumberOfDofs();
       TEST_EXIT(ndof)("no n_dof or basFcts->n_dof\n");
+
       for (int i = 0; i < mesh->getNumberOfDOFAdmin(); i++) {
 	admin_local = &(mesh->getDofAdmin(i));
 	int j = 0;
@@ -38,6 +40,7 @@ namespace AMDiS {
 	  break;
 	admin_local = NULL;
       }
+
       if (!admin_local) 
 	admin_local = mesh->createDOFAdmin(name, *ndof);
 
@@ -46,6 +49,7 @@ namespace AMDiS {
 
     feSpaces.push_back(this);
   }
+
   
 
   FiniteElemSpace::FiniteElemSpace()
@@ -98,7 +102,7 @@ namespace AMDiS {
 
   void FiniteElemSpace::clear()
   {
-    for (int i = 0; i < static_cast<int>(feSpaces.size()); i++) {
+    for (unsigned int i = 0; i < feSpaces.size(); i++) {
       if (feSpaces[i]) {
 	delete feSpaces[i];
 	feSpaces[i] = NULL;
diff --git a/AMDiS/src/Parameters.cc b/AMDiS/src/Parameters.cc
index 1c494da1cb1c65be5de83dd5595118541758066f..da889fd9cdad60b6f0d594e832cdb522f450f2b0 100644
--- a/AMDiS/src/Parameters.cc
+++ b/AMDiS/src/Parameters.cc
@@ -191,8 +191,8 @@ namespace AMDiS {
 	  }
 	  if (sstr.length() > 0)
 	    vecVal->push_back(atof(sstr.c_str()));
-       if(vecVal->size()==0)
-         WARNING("no values in parameter vector!\n");
+	  if (vecVal->size() == 0)
+	    WARNING("no values in parameter vector!\n");
 	}
 	break;
       case 'D': // list of int values, example parameter: {a,b,c,d,e}
@@ -221,7 +221,7 @@ namespace AMDiS {
 	  }
 	  if (sstr.length() > 0)
 	    vecVal->push_back(atoi(sstr.c_str()));
-       if(vecVal->size()==0)
+       if (vecVal->size() == 0)
          WARNING("no values in parameter vector!\n");
 	}
 	break;
@@ -691,11 +691,11 @@ namespace AMDiS {
     if (key.size() == 0 || par.size() == 0)
       return;
 
-    std::string file_str;
-    if(file != NULL)
+    std::string file_str = "";
+    if (file != NULL)
       file_str = std::string(file);
-    std::string fname_str;
-    if(fname != NULL)
+    std::string fname_str = "";
+    if (fname != NULL)
       fname_str = std::string(fname);
     singlett->addParam(key, par, file_str, line, fname_str);
 
diff --git a/AMDiS/src/parallel/MeshDistributor.cc b/AMDiS/src/parallel/MeshDistributor.cc
index eeeda478f1060184ca91e37eab7b885e25d1db33..187950aa6b5981b6d264ec2979a90e51e4c35d8a 100644
--- a/AMDiS/src/parallel/MeshDistributor.cc
+++ b/AMDiS/src/parallel/MeshDistributor.cc
@@ -41,11 +41,6 @@ namespace AMDiS {
     return (*dof1 < *dof2);
   }
 
-  bool cmpElement(MacroElement* lhs, MacroElement* rhs)
-  {
-    return lhs->getIndex() < rhs->getIndex();
-  }
-  
 
   MeshDistributor::MeshDistributor(std::string str)
     : probStat(0),
@@ -63,6 +58,7 @@ namespace AMDiS {
       repartitioningAllowed(false),
       nTimestepsAfterLastRepartitioning(0),
       repartCounter(0),
+      debugOutputDir(""),
       lastMeshChangeIndex(0)
   {
     FUNCNAME("MeshDistributor::ParalleDomainBase()");
@@ -74,6 +70,8 @@ namespace AMDiS {
     int tmp = 0;
     GET_PARAMETER(0, name + "->repartitioning", "%d", &tmp);
     repartitioningAllowed = (tmp > 0);
+
+    GET_PARAMETER(0, name + "->debug output dir", &debugOutputDir);    
   }
 
 
@@ -145,8 +143,8 @@ namespace AMDiS {
       GET_PARAMETER(0, "dbg->write part mesh", "%d", &writePartMesh);
 
       if (writePartMesh > 0) {
-	debug::writeElementIndexMesh(mesh, "elementIndex.vtu");
-	writePartitioningMesh("part.vtu");
+	debug::writeElementIndexMesh(mesh, debugOutputDir + "elementIndex.vtu");
+	writePartitioningMesh(debugOutputDir + "part.vtu");
       } else {
 	MSG("Skip write part mesh!\n");
       }
@@ -192,7 +190,7 @@ namespace AMDiS {
     ParallelDebug::testCommonDofs(*this, true);
     ParallelDebug::testGlobalIndexByCoords(*this);
 
-    debug::writeMesh(feSpace, -1, "macro_mesh");   
+    debug::writeMesh(feSpace, -1, debugOutputDir + "macro_mesh");   
 
     MSG("Debug mode tests finished!\n");
 #endif
@@ -210,15 +208,11 @@ namespace AMDiS {
     if (globalRefinement > 0) {
       refineManager->globalRefine(mesh, globalRefinement);
 
-#if (DEBUG != 0)
-      debug::writeMesh(feSpace, -1, "gr_mesh");
-#endif
-
       updateLocalGlobalNumbering();
 
      
-      // === Update periodic mapping, if there are periodic boundaries. ===
-      
+      // === Update periodic mapping, if there are periodic boundaries. ===     
+
       createPeriodicMap();
     }
 
@@ -497,7 +491,7 @@ namespace AMDiS {
     FUNCNAME("MeshDistributor::checkMeshChange()");    
 
 #if (DEBUG != 0)
-    debug::writeMesh(feSpace, -1, "before_check_mesh");
+    debug::writeMesh(feSpace, -1, debugOutputDir + "before_check_mesh");
 #endif
 
     // === If mesh has not been changed on all ranks, return. ===
@@ -554,7 +548,7 @@ namespace AMDiS {
     } while (recvAllValues != 0);
 
 #if (DEBUG != 0)
-    debug::writeMesh(feSpace, -1, "mesh");
+    debug::writeMesh(feSpace, -1, debugOutputDir + "mesh");
 #endif
 
     INFO(info, 8)("Parallel mesh adaption needed %.5f seconds\n", 
@@ -575,10 +569,10 @@ namespace AMDiS {
     nTimestepsAfterLastRepartitioning++;
 
     if (repartitioningAllowed) {
-      //      if (nTimestepsAfterLastRepartitioning >= 20) {
+      if (nTimestepsAfterLastRepartitioning >= 20) {
 	repartitionMesh();
 	nTimestepsAfterLastRepartitioning = 0;
-	//      }
+      }
     }
   }
 
@@ -995,16 +989,15 @@ namespace AMDiS {
       return;
 
 #if (DEBUG != 0)
-    //    if (repartCounter == 0) {
- {
+    if (repartCounter == 0) {
       std::stringstream oss;
-      oss << "partitioning-" << repartCounter << ".vtu";
+      oss << debugOutputDir << "partitioning-" << repartCounter << ".vtu";
       DOFVector<double> tmpa(feSpace, "tmp");
       tmpa.set(mpiRank);
       VtkWriter::writeFile(&tmpa, oss.str());
       
       repartCounter++;
- }
+    }
 
     MSG("USED-SIZE A: %d\n", mesh->getDofAdmin(0).getUsedDofs());
 #endif
@@ -1049,9 +1042,7 @@ namespace AMDiS {
       }
     }
 
-    bool (*fn_pt)(MacroElement*, MacroElement*) = cmpElement;
-    std::set<MacroElement* , bool(*)(MacroElement*, MacroElement*)> allMacroEl(fn_pt);
-
+    std::set<MacroElement*> allMacroEl;
     for (std::set<MacroElement*>::iterator it = newMacroEl.begin(); 
 	 it != newMacroEl.end(); ++it)
       allMacroEl.insert(*it);
@@ -1195,7 +1186,7 @@ namespace AMDiS {
 
 #if (DEBUG != 0)
     std::stringstream oss;
-    oss << "partitioning-" << repartCounter << ".vtu";    
+    oss << debugOutputDir << "partitioning-" << repartCounter << ".vtu";    
     DOFVector<double> tmpa(feSpace, "tmp");
     tmpa.set(mpiRank);
     VtkWriter::writeFile(&tmpa, oss.str());
@@ -1220,7 +1211,7 @@ namespace AMDiS {
     ParallelDebug::testCommonDofs(*this, true);
     ParallelDebug::testGlobalIndexByCoords(*this);
 
-    debug::writeMesh(feSpace, -1, "macro_mesh");   
+    debug::writeMesh(feSpace, -1, debugOutputDir + "macro_mesh");   
 
     MSG("Debug mode tests finished!\n");
 #endif
@@ -1801,13 +1792,13 @@ namespace AMDiS {
     
 #if (DEBUG != 0)
     std::stringstream oss;
-    oss << "elementIndex-" << mpiRank << ".vtu";
+    oss << debugOutputDir << "elementIndex-" << mpiRank << ".vtu";
 
     debug::writeElementIndexMesh(mesh, oss.str());
     debug::testSortedDofs(mesh, elMap);
     ParallelDebug::testCommonDofs(*this, true);
     ParallelDebug::testGlobalIndexByCoords(*this);
-    ParallelDebug::writeDebugFile(*this, "mpi-dbg", "dat");
+    ParallelDebug::writeDebugFile(*this, debugOutputDir + "mpi-dbg", "dat");
     
 #if 0
     MSG("------------- Debug information -------------\n");
diff --git a/AMDiS/src/parallel/MeshDistributor.h b/AMDiS/src/parallel/MeshDistributor.h
index 6b9dff24e08ad8e980932e92aabd9d73cfbad4b2..195afa71ed2080986f3322c67d338fb278e5e2ac 100644
--- a/AMDiS/src/parallel/MeshDistributor.h
+++ b/AMDiS/src/parallel/MeshDistributor.h
@@ -571,6 +571,9 @@ namespace AMDiS {
 
     int repartCounter;
 
+    /// Directory name where all debug output files should be written to.
+    std::string debugOutputDir;
+
     /** \brief
      * Stores the mesh change index. This is used to recognize changes in the mesh 
      * structure (e.g. through refinement or coarsening managers).