Index: trunk/FACT++/src/Fits.cc
===================================================================
--- trunk/FACT++/src/Fits.cc	(revision 10926)
+++ trunk/FACT++/src/Fits.cc	(revision 10927)
@@ -148,6 +148,25 @@
 	{
 		string factTableName = "FACT-" + tableName;
-		fTable = fFile->addTable(factTableName, 0, allNames, allDataTypes, allUnits);
-		fTable->makeThisCurrent();
+		//first, let's check if the table already exist in the file
+		vector<string> tryToLoadName;
+		tryToLoadName.push_back(factTableName);
+		fFile->read(tryToLoadName);
+	    const multimap< string, CCfits::ExtHDU * >& extMap = fFile->extension();
+	    if (extMap.find(factTableName) == extMap.end())
+	    {
+	        for (multimap<string, CCfits::ExtHDU*>::const_iterator it=extMap.begin(); it!= extMap.end(); it++)
+	            fMess->Debug(it->first);
+	        fTable = fFile->addTable(factTableName, 0, allNames, allDataTypes, allUnits);
+	    }
+	    else
+	    {
+	        fTable = dynamic_cast<CCfits::Table*>(extMap.find(factTableName)->second);
+	    }
+	    if (!fTable)
+	    {
+	        fMess->Error("The table " + factTableName + " could not be created nor loaded. skipping it");
+	        return;
+	    }
+	    fTable->makeThisCurrent();
 		fCopyBuffer = new unsigned char[fTotalNumBytes]; 
 		fNumRows = fTable->rows();
@@ -178,4 +197,5 @@
 			updating = true;
 		}
+
 	}
 	catch(CCfits::FitsException e)
@@ -301,5 +321,8 @@
 	WriteSingleHeaderKey("TSTOP", fEndMjD, "Time of the last receied data");
 	if (fFile != NULL && fOwner)
-		delete fFile;
+	{
+//	    fFile->flush();
+	    delete fFile;
+	}
 	fFile = NULL;
 	if (fCopyBuffer != NULL)
Index: trunk/FACT++/src/dataLogger.cc
===================================================================
--- trunk/FACT++/src/dataLogger.cc	(revision 10926)
+++ trunk/FACT++/src/dataLogger.cc	(revision 10927)
@@ -933,6 +933,9 @@
             }
             //check if daily files should be closed and reopened.
+            //FIXME when Time().h() == 12, the actual time is 2pm
             if (Time().h() == 12 && !resetDone)
             {
+                if (fDebugIsOn)
+                    Debug("Change of day detected. Closing daily files and restarting the dataLogger");
                 int cState = GetCurrentState();
                 GoToReadyPlease();
@@ -952,5 +955,8 @@
             }
             else
-                resetDone = false;
+ //           {
+ //               if (Time().h() != 12 && resetDone)
+                    resetDone = false;
+//            }
             if (fStatsPeriodDuration == 0.0f)
             {
@@ -2093,5 +2099,10 @@
         return;
     }
-    string groupName = CompileFileName(fRunFilePath, Time(), runNumber, "", "fits");
+    string groupName;
+    if (runNumber != 0)
+        groupName = CompileFileName(fRunFilePath, Time(), runNumber, "", "fits");
+    else
+        groupName = CompileFileName(fNightlyFilePath, Time(), "", "fits");
+
     CCfits::Table* groupTable;
     int maxCharLength = 50;//FILENAME_MAX;
