diff --git a/src/Makefile b/src/Makefile
index 0dc964e7c1759f53406d29b3f0a684f58d14458a..20d0396acdd607c47bc402908b900b6064f76638 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -12,7 +12,7 @@
 TARGET = scdaq
 
 # source files
-SOURCES = config.cc DmaInputFilter.cc elastico.cc FileDmaInputFilter.cc InputFilter.cc outputBySize.cc outputByOrbit.cc processor.cc scdaq.cc session.cc slice.cc WZDmaInputFilter.cc MicronDmaInputFilter.cc
+SOURCES = config.cc DmaInputFilter.cc elastico.cc FileDmaInputFilter.cc InputFilter.cc OutputBySize.cc OutputByOrbit.cc processor.cc scdaq.cc session.cc slice.cc WZDmaInputFilter.cc MicronDmaInputFilter.cc
 C_SOURCES = wz_dma.c
 
 # work out names of object files from sources
@@ -57,14 +57,14 @@ ${TARGET}: ${OBJECTS}
 
 #test2.o : product.h test2.h
 
-scdaq.o:	processor.h elastico.h outputBySize.h outputByOrbit.h format.h server.h controls.h config.h session.h log.h
+scdaq.o:	processor.h elastico.h OutputBySize.h OutputByOrbit.h format.h server.h controls.h config.h session.h log.h
 config.o:	config.h log.h
 DmaInputFilter.o:	DmaInputFilter.h slice.h
 elastico.o:	elastico.h format.h slice.h controls.h log.h
 FileDmaInputFilter.o:	FileDmaInputFilter.h InputFilter.h log.h
 InputFilter.o:	InputFilter.h log.h
-outputBySize.o:	outputBySize.h slice.h log.h
-outputByOrbit.o:	outputByOrbit.h slice.h log.h
+outputBySize.o:	OutputBySize.h slice.h log.h
+outputByOrbit.o:	OutputByOrbit.h slice.h log.h
 processor.o:	processor.h slice.h format.h log.h bril_histo.h
 session.o:	session.h log.h
 slice.o: 	slice.h
diff --git a/src/outputByOrbit.cc b/src/OutputByOrbit.cc
similarity index 94%
rename from src/outputByOrbit.cc
rename to src/OutputByOrbit.cc
index e398c23db6fdb38fce5c599da74881681cb13cc1..d7a5873fed0d5c3a74d541229f075038260bd5d4 100644
--- a/src/outputByOrbit.cc
+++ b/src/OutputByOrbit.cc
@@ -1,7 +1,7 @@
 #include <system_error>
 #include <fstream>
 #include <string>
-#include "outputByOrbit.h"
+#include "OutputByOrbit.h"
 #include "slice.h"
 #include "log.h"
 #include "tools.h"
@@ -59,7 +59,7 @@ OutputByOrbitStream::OutputByOrbitStream( const std::string output_filename_base
 void* OutputByOrbitStream::OutputFixedOrbits( Slice& out ) {
 
   uint32_t orbitN = out.get_firstOrbitN();   
-  std::cout << orbitN << std::endl; 
+  //std::cout << orbitN << std::endl;
   uint32_t new_index = uint32_t(orbitN/conf.getNOrbitsPerFile());
   size_t n = 0;
   bool already_opened=false;
@@ -67,7 +67,7 @@ void* OutputByOrbitStream::OutputFixedOrbits( Slice& out ) {
 
     if ( control.running.load(std::memory_order_acquire) || control.output_force_write ) { //i.e should be writing data
       if (current_run_number != control.run_number) {
-
+	close_and_move_file(); 
 	open_file(new_index);
 	n = fwrite( out.begin(), 1, out.size(), outFile.getFile() );
 
@@ -82,10 +82,10 @@ void* OutputByOrbitStream::OutputFixedOrbits( Slice& out ) {
 	n = fwrite( out.begin(), 1, out.size(), outFile.getFile() );
 
       } 
+      current_file_size +=n;    
+    }else{ // i.e should not currently be writing data
+      close_and_move_file();//once for each open file (should be 2)
     }
-    current_file_size +=n;    
-  }else{ // i.e should not currently be writing data
-    close_and_move_file();//once for each open file (should be 2)
   }
 }
 
@@ -125,6 +125,7 @@ void OutputByOrbitStream::close_and_move_file() //Used for fixedNorbits per file
   if ( rename(current_file_name.c_str(), target_file_name.c_str()) < 0 ) {
     LOG(ERROR) << tools::strerror("File rename failed");
   }
+  current_run_number = control.run_number;
 }
 
 void OutputByOrbitStream::open_file(uint32_t index_) //Used for fixedNorbits per file option
diff --git a/src/outputByOrbit.h b/src/OutputByOrbit.h
similarity index 100%
rename from src/outputByOrbit.h
rename to src/OutputByOrbit.h
diff --git a/src/outputBySize.cc b/src/OutputBySize.cc
similarity index 99%
rename from src/outputBySize.cc
rename to src/OutputBySize.cc
index b7c6d3c0a7af199225340de67ebc69b2c8bdcb4b..761f62043148167f821dec7b163bd36ddc808f9c 100644
--- a/src/outputBySize.cc
+++ b/src/OutputBySize.cc
@@ -1,7 +1,7 @@
 #include <system_error>
 #include <fstream>
 #include <string>
-#include "outputBySize.h"
+#include "OutputBySize.h"
 #include "slice.h"
 #include "log.h"
 #include "tools.h"
diff --git a/src/outputBySize.h b/src/OutputBySize.h
similarity index 100%
rename from src/outputBySize.h
rename to src/OutputBySize.h
diff --git a/src/processor.cc b/src/processor.cc
index 621c018687e18b05156118139d74d8e62bdd8316..6b5765392a38c3e59e05c7d065acbe2127c857e4 100644
--- a/src/processor.cc
+++ b/src/processor.cc
@@ -338,6 +338,5 @@ void* StreamProcessor::operator()( void* item ){
 	Slice& out = *Slice::allocate( 2*max_size);
 	process(input, out);
 	Slice::giveAllocated(&input);
-
 	return &out;
 }
diff --git a/src/scdaq.cc b/src/scdaq.cc
index f53386367fb20503fa7a0b63e982b34519c1dd24..21f4c28a9d0b825c957131b43fbe52ef9e54f1f7 100644
--- a/src/scdaq.cc
+++ b/src/scdaq.cc
@@ -21,8 +21,8 @@
 #include "DmaInputFilter.h"
 #include "processor.h"
 #include "elastico.h"
-#include "outputBySize.h"
-#include "outputByOrbit.h"
+#include "OutputBySize.h"
+#include "OutputByOrbit.h"
 #include "format.h"
 #include "server.h"
 #include "controls.h"
@@ -42,7 +42,8 @@ int run_pipeline( int nbThreads, ctrl& control, config& conf )
   uint32_t prescaleFactor = conf.getPrescaleFactor();  
   // Create empty input reader, will assign later when we know what is the data source
   std::shared_ptr<InputFilter> input_filter;
-
+  std::shared_ptr<OutputByOrbitStream> output_stream_by_orbit;
+  std::shared_ptr<OutputBySizeStream> output_stream_by_size;
   // Create the pipeline
   tbb::pipeline pipeline;
 
@@ -92,11 +93,11 @@ int run_pipeline( int nbThreads, ctrl& control, config& conf )
 
   // Create file-writing stage and add it to the pipeline
   if ( conf.getNOrbitsPerFile() ){
-  OutputByOrbitStream output_stream( conf.getOutputFilenameBase(), conf.getOutputFilenamePrefix(), control, conf );
-  pipeline.add_filter( output_stream );
+    output_stream_by_orbit = std::make_shared<OutputByOrbitStream>( conf.getOutputFilenameBase(), conf.getOutputFilenamePrefix(), control, conf );
+    pipeline.add_filter( *output_stream_by_orbit );
   }else{ 
-  OutputBySizeStream output_stream( conf.getOutputFilenameBase(), conf.getOutputFilenamePrefix(), control);
-  pipeline.add_filter( output_stream );
+    output_stream_by_size = std::make_shared<OutputBySizeStream>( conf.getOutputFilenameBase(), conf.getOutputFilenamePrefix(), control);
+    pipeline.add_filter( *output_stream_by_size );
   }