diff --git a/matlab/evaluate_static_model.m b/matlab/evaluate_static_model.m
index e505ce6aede15edf898ff51af36f7baf4f6e30e7..e3758378d467cdc28cc47bcdf6bab6f3da6adb39 100644
--- a/matlab/evaluate_static_model.m
+++ b/matlab/evaluate_static_model.m
@@ -53,18 +53,13 @@ else
         residuals = zeros(M.endo_nbr,1);
         T = NaN(M.block_structure_stat.tmp_nbr, 1);
         for b = 1:length(M.block_structure_stat.block)
-            mfsb = M.block_structure_stat.block(b).variable;
-            % blocks that can be directly evaluated (mfsb is empty)
-            % have zero residuals by construction
-            if M.block_structure_stat.block(b).Simulation_Type ~= 1 && ...
-                    M.block_structure_stat.block(b).Simulation_Type ~= 2
-                [r, ~, T] = feval(fh_static,b,ys,exo_ss,params,T);
-                residuals(mfsb) = r;
-            else
-                %need to evaluate the recursive blocks to compute the
-                %temporary terms
-                [~, ~, T] = feval(fh_static,b,ys,exo_ss,params,T);
+            [r, yy, T] = feval(fh_static,b,ys,exo_ss,params,T);
+            if M.block_structure_stat.block(b).Simulation_Type == 1 || ... % evaluateForward
+               M.block_structure_stat.block(b).Simulation_Type == 2        % evaluateBackward
+                vidx = M.block_structure_stat.block(b).variable;
+                r = yy(vidx) - ys(vidx);
             end
+            residuals(M.block_structure_stat.block(b).equation) = r;
         end
         if nargout==3
             jacob=NaN(length(ys));
diff --git a/matlab/resid.m b/matlab/resid.m
index 22cc2f8749b60b19d49c10ad62d6719f02fd9294..19d316b56472a3208f4a2b505f16df5c70f2c466 100644
--- a/matlab/resid.m
+++ b/matlab/resid.m
@@ -67,31 +67,9 @@ if options_.steadystate_flag
 end
 
 % Compute the residuals
-if options_.block && ~options_.bytecode
-    z = zeros(M_.endo_nbr,1);
-    T = NaN(M_.block_structure_stat.tmp_nbr, 1);
-    for i = 1:length(M_.block_structure_stat.block)
-        [r, yy, T, g] = feval([M_.fname '.static'],...
-                              i,...
-                              oo_.steady_state,...
-                              [oo_.exo_steady_state; ...
-                               oo_.exo_det_steady_state], M_.params, T);
-        if M_.block_structure_stat.block(i).Simulation_Type == 1 || ... % evaluateForward
-           M_.block_structure_stat.block(i).Simulation_Type == 2        % evaluateBackward
-            vidx = M_.block_structure_stat.block(i).variable;
-            r = yy(vidx) - oo_.steady_state(vidx);
-        end
-        idx = M_.block_structure_stat.block(i).equation;
-        z(idx) = r;
-    end
-elseif options_.bytecode
-    z = bytecode('evaluate','static');
-else
-    z = feval([M_.fname '.static'],...
-              oo_.steady_state,...
-              [oo_.exo_steady_state; ...
-               oo_.exo_det_steady_state], M_.params);
-end
+z = evaluate_static_model(oo_.steady_state, [oo_.exo_steady_state; ...
+                                             oo_.exo_det_steady_state], ...
+                          M_.params, M_, options_);
 
 M_.Sigma_e = Sigma_e;
 
@@ -123,4 +101,4 @@ if nargout == 0
     skipline(2)
 end
 
-oo_.steady_state = steady_state_old;
\ No newline at end of file
+oo_.steady_state = steady_state_old;