diff --git a/da/tools/pipeline.py b/da/tools/pipeline.py
index 944662f8a19940ef6bc18638f7430414661278ba..b8683bf8ff6a70102bc0d1b1c435c2e4cfe7c59d 100755
--- a/da/tools/pipeline.py
+++ b/da/tools/pipeline.py
@@ -222,7 +222,7 @@ def SampleOneCycle(DaCycle,Samples,StateVector, ObservationOperator,lag):
     # Read forecast model samples that were written to NetCDF files by each member, also add the obs to the statevector
     # Note that obs will only be added to the statevector is either this is the first step (restart=False), or lag==nlag
 
-    if lag == nlag-1 or DaCycle['time.restart']==True :
+    if lag == DaCycle['nlag']-1 or DaCycle['time.restart']==True :
 
         silent = False
         members = StateVector.EnsembleMembers[lag]