Index: trunk/FACT++/scripts/CheckUnderflow.js
===================================================================
--- trunk/FACT++/scripts/CheckUnderflow.js	(revision 16742)
+++ trunk/FACT++/scripts/CheckUnderflow.js	(revision 16743)
@@ -84,8 +84,8 @@
     dim.send("FAD_CONTROL/SET_FILE_FORMAT", 0);
 
-    var sub_startrun = new Subscription("FAD_CONTROL/START_RUN");
-    var sruns = sub_startrun.get(5000);
-
-    if (dim.state("FAD_CONTROL").name=="RunInProgress" || sruns.obj['run']!=-1)
+    var sub_runs = new Subscription("FAD_CONTROL/RUNS");
+    var sruns = sub_runs.get(5000, false);
+
+    if (dim.state("FAD_CONTROL").name=="RunInProgress" || sruns.qos==1)
     {
         dim.send("FAD_CONTROL/CLOSE_OPEN_FILES");
@@ -93,14 +93,17 @@
 
         console.out("Waiting for open files to be closed...");
-        v8.timeout(60000, function() { if (sub_startrun.get().obj['run']==-1) return true; });
+        v8.timeout(60000, function() { if (sub_runs.get(false).qos==0) return true; });
 
         // Although the file should be closed now, the processing might still be on-going
         // and delayed events might be received. The only fix for that issue is to
         // add the run number to the data we are waiting for
-        v8.sleep(10000);
-    }
+        v8.sleep(5000);
+    }
+
+    sub_runs.close();
 
     console.out("Starting drs-gain... waiting for new event");
 
+    var sub_startrun = new Subscription("FAD_CONTROL/START_RUN");
     var sub_incomplete = new Subscription("FAD_CONTROL/INCOMPLETE");
     var sub_connections = new Subscription("FAD_CONTROL/CONNECTIONS");
