while(true)
     {
-      if( (!inFile.is_open()) && inFiles.size() == 0 ) return nequileft;
+      vector<infiledesc>::iterator inFileIt = getNextInfile(excludeFileHashes);
 
-      while( (!inFile.is_open()) && inFiles.size() > 0 ) {
-       bool excludethisfile=false;
+      if( (!inFile.is_open()) && inFileIt == inFiles.end() ) return nequileft;
 
-       openFileDesc = inFiles.back();
+      while( (!inFile.is_open()) && inFiles.size() > 0 ) {
+       openFileDesc = *inFileIt;
 
-       if (excludeFileHashes != NULL)
-         for (vector<unsigned long>::iterator exit = excludeFileHashes->begin(); exit != excludeFileHashes->end(); ++exit)
-           if ( *exit == hash(inFiles.back().filename) ) {
-             excludethisfile = true;
-             break;
-           }
-             
-       if ( ! excludethisfile ) {
-         if(log) *log << "CCACHE: Opening dat-file: " << inFiles.back().filename << endl << flush;
-         inFile.open( (DATADIR + "/" + inFiles.back().filename).c_str(), std::ios::binary );
-       }
-       else
-         if(log) *log << "CCACHE: Excluded dat-file: " << inFiles.back().filename << endl << flush;
+       if(log) *log << "CCACHE: Opening dat-file: " << inFileIt->filename << endl << flush;
+       inFile.open( (DATADIR + "/" + inFileIt->filename).c_str(), std::ios::binary );
        
-       inFiles.pop_back();
+       inFiles.erase(inFileIt);
        
        if( !inFile.is_open() ) continue;
 
     headerStore.pop_back();
   }
 }
+
+vector<infiledesc>::iterator configcache::getNextInfile(vector<unsigned long> *excludeFileHashes) {
+  for (vector<infiledesc>::iterator init = inFiles.begin(); init != inFiles.end(); ++init) {
+    if (excludeFileHashes != NULL) {
+      bool excludethisfile = false;
+
+      for (vector<unsigned long>::iterator exit = excludeFileHashes->begin(); exit != excludeFileHashes->end(); ++exit)
+       if ( *exit == hash(init->filename) ) {
+         excludethisfile = true;
+         break;
+       }
+
+      if (excludethisfile)
+       continue;
+    }
+    return init;
+  }
+  return inFiles.end();
+}
 
   string getOutFileName() { return outFileName.str(); }
   string getInFileName() { return DATADIR + "/" + openFileDesc.filename; }
   static unsigned long hash(const string& str);
+  void closeInFile() { inFile.close(); }
+  int inFilesLeft() { return inFiles.size(); }
 
  private:
   ostream* log;
   void deleteHeaderStore();
 
   bool readAllHeaders();
+
+  vector<infiledesc>::iterator getNextInfile(vector<unsigned long> *excludeFileHashes);
 };
 
 #endif
 
   return readret; 
 }
 
+int hypercache::read1CForEqui() {
+  int readret = C->readConfig(NULL);
+  C->closeInFile();
+  return readret;
+}
+
 void hypercache::writeC() {
   C->writeConfig();
   activeCFile = fileOfPath( C->getOutFileName().substr( 0, C->getOutFileName().length()-4 ) );
 
   static void *getHeaderC(const string& headerid) { C->getHeader(headerid); }
 
   static void finalize();
+
+  static int read1CForEqui();
+  static int CFilesLeft() { return C->inFilesLeft(); }
   
  private:
   struct para{
 
   protected:
     o815 *O815;
     ostream *log;
-    int nequi, nskip;
+    int nequi, nskip, confmemSize;
   };
 
   struct {
 
 #include "latlib/hypercache.h"
 #include "latlib/progress.h"
 
-o815::sim::sim(o815 *_O815, const int& confmemSize) {
+o815::sim::sim(o815 *_O815, const int& _confmemSize) {
   O815 = _O815;
   log = O815->out->log;
-  hypercache::initC(O815->programid, O815->comargs.nequi, O815->comargs.nskip, O815->comargs.confcache.first, &confMem, confmemSize, O815->comargs.confcache.second, log);
+  hypercache::initC(O815->programid, O815->comargs.nequi, O815->comargs.nskip, O815->comargs.confcache.first, &confMem, _confmemSize, O815->comargs.confcache.second, log);
   toEquilibrate = true;
   nequi = O815->comargs.nequi;
   nskip = O815->comargs.nskip;
+  confmemSize = confmemSize;
 }
 
 void o815::sim::nextConfig() {
   int nequileft = hypercache::readC();
 
   if ( nequileft != -1 ) {
-    if(toEquilibrate) {
+    /* try to use excluded config-file for equilibration */
+    if (toEquilibrate && hypercache::CFilesLeft() > 0) {
+      int exnequileft;
+      char *tmpconfig = (char*) malloc(confmemSize);
+
+      memcpy (tmpconfig, confMem, confmemSize);
+      exnequileft = hypercache::read1CForEqui();
+
+      if (exnequileft < nequileft) {
+       *log << "SIM: Found suitable excluded config-file configuration for equilibration." << endl << flush;
+       nequileft = exnequileft;
+      }
+      else {
+       *log << "SIM: Could not find suitable excluded config-file configuration for equilibration." << endl << flush;
+       memcpy (confMem, tmpconfig, confmemSize);
+      }
+
+      free(tmpconfig);
+    }
+
+    if(toEquilibrate && nequileft > 0) {
       _reset();
       *log << "SIM: Starting equilibration." << endl << flush;
       if (nequileft != nequi)
        _makeSweep(1);
        while( equiProg.madeStep(iequi) ) *log << "SIM: " << equiProg.done()*100 << "% of equilibration done." << endl << flush;
       }
-    }  
+    }
+       
     _makeSweep(nskip);
     hypercache::writeC();
   }