diff --git a/CEP/DP3/DPPP/include/DPPP/DPStep.h b/CEP/DP3/DPPP/include/DPPP/DPStep.h
index fc936d4a5cc5330a6a1ec7ca89a8c1a9a1cd5940..2628ca45e56f83e0d0398a9e3b20f4146becbaf9 100644
--- a/CEP/DP3/DPPP/include/DPPP/DPStep.h
+++ b/CEP/DP3/DPPP/include/DPPP/DPStep.h
@@ -67,6 +67,11 @@ namespace LOFAR {
       // Define the shared pointer for this type.
       typedef shared_ptr<DPStep> ShPtr;
 
+      // Constructor to initialize.
+      DPStep()
+        : itsPrevStep(0)
+      {}
+
       // Destructor.
       virtual ~DPStep();
 
diff --git a/CEP/DP3/DPPP/src/AORFlagger.cc b/CEP/DP3/DPPP/src/AORFlagger.cc
index 868459b0683f68b76a95c6453d87390002f588ce..01953aab44e87944cc014f3515ebb85f9627ef82 100644
--- a/CEP/DP3/DPPP/src/AORFlagger.cc
+++ b/CEP/DP3/DPPP/src/AORFlagger.cc
@@ -271,6 +271,7 @@ namespace LOFAR {
 
     void AORFlagger::addToMS (const string& msName)
     {
+      getPrevStep()->addToMS(msName);
       itsTimer.start();
       if (itsDoRfiStats) {
         itsQualityTimer.start();
diff --git a/CEP/DP3/DPPP/src/DPRun.cc b/CEP/DP3/DPPP/src/DPRun.cc
index 90dffad23579d33fd11ae3fc03bafb0aabe74f8d..acffbffba6811b01837b825cf1c8ca31096e5ed5 100644
--- a/CEP/DP3/DPPP/src/DPRun.cc
+++ b/CEP/DP3/DPPP/src/DPRun.cc
@@ -172,6 +172,9 @@ namespace LOFAR {
       DPLOG_INFO_STR ("Finishing processing ...");
       firstStep->finish();
       // Give all steps the option to add something to the MS written.
+      // It starts with the last step to get the name of the output MS,
+      // but each step must first call its previous step before
+      // it adds something itself.
       lastStep->addToMS("");
 
       // Show the counts where needed.
diff --git a/CEP/DP3/DPPP/src/DPStep.cc b/CEP/DP3/DPPP/src/DPStep.cc
index 79b6d90fd5fa532933bbd52849e27b884ff6a4b3..3bd88613dda200b2a50eecbed6bbba4588220790 100644
--- a/CEP/DP3/DPPP/src/DPStep.cc
+++ b/CEP/DP3/DPPP/src/DPStep.cc
@@ -46,7 +46,7 @@ namespace LOFAR {
 
     void DPStep::addToMS (const string& msName)
     {
-      itsPrevStep->addToMS(msName);
+      if (itsPrevStep) itsPrevStep->addToMS(msName);
     }
 
     void DPStep::showCounts (std::ostream&) const
diff --git a/CEP/DP3/DPPP/src/Filter.cc b/CEP/DP3/DPPP/src/Filter.cc
index 3cc96358854d459b6ab8255a7d3035b4bcaa82db..131367cc0c467df645e1892fc6a5a4fd976d4f14 100644
--- a/CEP/DP3/DPPP/src/Filter.cc
+++ b/CEP/DP3/DPPP/src/Filter.cc
@@ -249,6 +249,7 @@ namespace LOFAR {
 
     void Filter::addToMS (const string& msName)
     {
+      getPrevStep()->addToMS(msName);
       if (! itsRemoveAnt) {
         return;
       }