diff --git a/matlab/DsgeSmoother.m b/matlab/DsgeSmoother.m
index 722b80959da728b4fb517f0d53f9058e53d7a7ba..ee92a99031b3f4872451bc04766fa3f0a6e09d71 100644
--- a/matlab/DsgeSmoother.m
+++ b/matlab/DsgeSmoother.m
@@ -430,7 +430,7 @@ else
                 % period ahead (so if regimestart was [1 5] it should be [1 4]
                 % in out
                 %         end
-                bbb(oo_.dr.inv_order_var,k) = out.piecewise(1,:);
+                bbb(oo_.dr.inv_order_var,k) = out.piecewise(1,:) - out.ys';
             end
         end
         % do not overwrite accurate computations using reduced st. space
@@ -475,7 +475,7 @@ else
             % in out
             %         end
             for jnk=1:options_.nk
-                aaa(jnk,oo_.dr.inv_order_var,k+jnk-1) = out.piecewise(jnk,:);
+                aaa(jnk,oo_.dr.inv_order_var,k+jnk-1) = out.piecewise(jnk,:) - out.ys';
             end
         end
         aK=aaa;
diff --git a/matlab/missing_DiffuseKalmanSmootherH3_Z.m b/matlab/missing_DiffuseKalmanSmootherH3_Z.m
index a4d8e7e971cdab18337e7d401bb632710b954e9b..d585d3ca4eae6045694abd4ba29250c72de5d721 100644
--- a/matlab/missing_DiffuseKalmanSmootherH3_Z.m
+++ b/matlab/missing_DiffuseKalmanSmootherH3_Z.m
@@ -433,7 +433,7 @@ while notsteady && t<smpl
             Pf          = P(:,:,t+1);
         end
         aK(1,:,t+1) = a1(:,t+1);
-        if ~isempty(nk) && nk>1 && isoccbin 
+        if ~isempty(nk) && nk>1 && isoccbin && (t>=first_period_occbin_update || isinf(first_period_occbin_update))
             opts_simul = occbin_options.opts_regime;
             opts_simul.SHOCKS = zeros(nk,M_.exo_nbr);
             if smoother_redux
@@ -455,11 +455,11 @@ while notsteady && t<smpl
                 end
                 PK(jnk,:,:,t+jnk) = Pf;
             end
-            if isoccbin 
+            if isoccbin && (t>=first_period_occbin_update || isinf(first_period_occbin_update))
                 if smoother_redux
-                    aK(jnk,:,t+jnk) = out.piecewise(jnk,oo_.dr.order_var(oo_.dr.restrict_var_list));
+                    aK(jnk,:,t+jnk) = out.piecewise(jnk,oo_.dr.order_var(oo_.dr.restrict_var_list)) - out.ys(oo_.dr.order_var(oo_.dr.restrict_var_list))';
                 else
-                    aK(jnk,oo_.dr.inv_order_var,t+jnk) = out.piecewise(jnk,:);
+                    aK(jnk,oo_.dr.inv_order_var,t+jnk) = out.piecewise(jnk,:) - out.ys';
                 end
             elseif jnk>1
                 aK(jnk,:,t+jnk) = T*dynare_squeeze(aK(jnk-1,:,t+jnk-1));