diff --git a/matlab/dr_block.m b/matlab/dr_block.m
index ce28abdb61ed05a82ecd65aac1d2526a7c0abc87..bb51b72610bbb94f35760680f8d37d2a65c17669 100644
--- a/matlab/dr_block.m
+++ b/matlab/dr_block.m
@@ -77,8 +77,7 @@ else
     it_=M_.maximum_lag+1;
     y=dynvars_from_endo_simul(z, it_, M_);
     for blk = 1:length(M_.block_structure.block)
-        funcname = sprintf('%s.block.dynamic_%d', M_.fname, blk);
-        [~, T, data(blk).g1, data(blk).g1_x, data(blk).g1_xd, data(blk).g1_o]=feval(funcname, y, zx, M_.params, dr.ys, T, it_, true);
+        [~, ~, T, data(blk).g1, data(blk).g1_x, data(blk).g1_xd, data(blk).g1_o]=feval([M_.fname '.dynamic'], blk, y, zx, M_.params, dr.ys, T, it_, true);
     end
 end
 dr.full_rank = 1;
diff --git a/matlab/dynare_solve_block_or_bytecode.m b/matlab/dynare_solve_block_or_bytecode.m
index 3fafaf0d12688d401c03c8c9e418d6e251eb69ba..072e43cdfa3a15e0d28999a8aef4530ad8ae7985 100644
--- a/matlab/dynare_solve_block_or_bytecode.m
+++ b/matlab/dynare_solve_block_or_bytecode.m
@@ -37,7 +37,7 @@ if options.block && ~options.bytecode
                 ss(M.block_structure_stat.block(b).variable) = y;
             else
                 n = length(M.block_structure_stat.block(b).variable);
-                [ss, T, ~, check] = solve_one_boundary([M.fname '.block.static_' int2str(b)], ss, exo, ...
+                [ss, T, ~, check] = solve_one_boundary([M.fname '.static' ], ss, exo, ...
                                                        params, [], T, M.block_structure_stat.block(b).variable, n, 1, false, b, 0, options.simul.maxit, ...
                                                        options.solve_tolf, ...
                                                        options.slowc, 0, options.solve_algo, true, false, false, M, options, []);
@@ -47,8 +47,9 @@ if options.block && ~options.bytecode
                 end
             end
         end
-        % In particular, the following updates the temporary terms vector (for the dynare_solve case)
-        [r, x, T, g1] = feval([M.fname '.static'], b, ss, exo, params, T);
+        % Compute endogenous if the block is of type evaluate forward/backward
+        % Also update the temporary terms vector (needed for the dynare_solve case)
+        [~, x, T, g1] = feval([M.fname '.static'], b, ss, exo, params, T);
     end
 elseif options.bytecode
     if options.solve_algo > 4
diff --git a/matlab/lnsrch1_wrapper_one_boundary.m b/matlab/lnsrch1_wrapper_one_boundary.m
index 6b47975903cbf4a6056ea4fbcdeccc4cdc22035e..700bade4b13a5af8b4a6c09ef3fcdca3cd8af913 100644
--- a/matlab/lnsrch1_wrapper_one_boundary.m
+++ b/matlab/lnsrch1_wrapper_one_boundary.m
@@ -1,12 +1,12 @@
-function r = lnsrch1_wrapper_one_boundary(ya, ll_index, fname, y, x, params, steady_state, T, it_)
+function r = lnsrch1_wrapper_one_boundary(ya, ll_index, fname, blk, y, x, params, steady_state, T, it_)
 % wrapper for solve_one_boundary m-file when it is used with a dynamic
 % model
 %
 % INPUTS
 %   ya                  [vector]        The endogenous of the current block
 %   ll_index            [vector]        M_.lead_lag_incidence(M_.maximum_endo_lag+1, :)
-%   fname               [string]        name of the file containing the block
-%                                       to simulate
+%   fname               [string]        name of the static/dynamic file
+%   blk                 [int]           block number
 %   y                   [vector]        Dynamic endogenous variables of the model
 %   x                   [matrix]        All the exogenous variables of the model
 %   params              [vector]        All the parameters of the model
@@ -40,4 +40,4 @@ function r = lnsrch1_wrapper_one_boundary(ya, ll_index, fname, y, x, params, ste
 % along with Dynare.  If not, see <http://www.gnu.org/licen
 
 y2(nonzeros(ll_index)) = ya(find(ll_index));
-[r, ~, g1]=feval(fname, y, x, params, steady_state, T, it_, false);
+[r, ~, ~, g1]=feval(fname, blk, y, x, params, steady_state, T, it_, false);
diff --git a/matlab/lnsrch1_wrapper_two_boundaries.m b/matlab/lnsrch1_wrapper_two_boundaries.m
index 4f6d903cef09390fa42cdf4b49e7a75a352a1c7a..989cd107e8f5c21635c0d02bfa72532692bedf5b 100644
--- a/matlab/lnsrch1_wrapper_two_boundaries.m
+++ b/matlab/lnsrch1_wrapper_two_boundaries.m
@@ -1,4 +1,4 @@
-function ra = lnsrch1_wrapper_two_boundaries(ya, fname, y, y_index, x, ...
+function ra = lnsrch1_wrapper_two_boundaries(ya, fname, blk, y, y_index, x, ...
                                              params, steady_state, T, periods, ...
                                              y_size, M_)
 % wrapper for solve_one_boundary m-file when it is used with a dynamic
@@ -8,8 +8,8 @@ function ra = lnsrch1_wrapper_two_boundaries(ya, fname, y, y_index, x, ...
 %   ya                  [vector]        The endogenous of the current block
 %   y_index             [vector of int] The index of the endogenous variables of
 %                                       the block
-%   fname               [string]        name of the file containing the block
-%                                       to simulate
+%   fname               [string]        name of the dynamic file
+%   blk                 [int]           block number
 %   y                   [matrix]        All the endogenous variables of the model
 %   x                   [matrix]        All the exogenous variables of the model
 %   params              [vector]        All the parameters of the model
@@ -51,5 +51,5 @@ function ra = lnsrch1_wrapper_two_boundaries(ya, fname, y, y_index, x, ...
 y(y_index, M_.maximum_lag+(1:periods)) = reshape(ya',length(y_index),periods);
 ra = NaN(periods*y_size, 1);
 for it_ = M_.maximum_lag+(1:periods)
-    [ra((it_-M_.maximum_lag-1)*y_size+(1:y_size)), ~, g1]=feval(fname, dynvars_from_endo_simul(y, it_, M_), x, params, steady_state, T(:, it_), it_, false);
+    [ra((it_-M_.maximum_lag-1)*y_size+(1:y_size)), ~, ~, g1]=feval(fname, blk, dynvars_from_endo_simul(y, it_, M_), x, params, steady_state, T(:, it_), it_, false);
 end
diff --git a/matlab/perfect-foresight-models/solve_block_decomposed_problem.m b/matlab/perfect-foresight-models/solve_block_decomposed_problem.m
index fe09633313436ccb010bd399208122952f89453d..be248f27f2a5ff2a34c38e965936807996f9671d 100644
--- a/matlab/perfect-foresight-models/solve_block_decomposed_problem.m
+++ b/matlab/perfect-foresight-models/solve_block_decomposed_problem.m
@@ -43,9 +43,9 @@ y=oo_.endo_simul;
 T=NaN(M_.block_structure.dyn_tmp_nbr, options_.periods+M_.maximum_lag+M_.maximum_lead);
 oo_.deterministic_simulation.status = 0;
 
+funcname = [ M_.fname '.dynamic'];
+
 for blk = 1:length(M_.block_structure.block)
-    funcname = sprintf('%s.block.dynamic_%d', M_.fname, blk);
-    
     recursive_size = M_.block_structure.block(blk).endo_nbr - M_.block_structure.block(blk).mfs;
     y_index = M_.block_structure.block(blk).variable((recursive_size+1):end);
 
@@ -64,7 +64,7 @@ for blk = 1:length(M_.block_structure.block)
         end
         for it_ = range
             y2 = dynvars_from_endo_simul(y, it_, M_);
-            [y2, T(:, it_)] = feval(funcname, y2, oo_.exo_simul, M_.params, oo_.steady_state, T(:, it_), it_, false);
+            [~, y2, T(:, it_)] = feval(funcname, blk, y2, oo_.exo_simul, M_.params, oo_.steady_state, T(:, it_), it_, false);
             y(find(M_.lead_lag_incidence(M_.maximum_endo_lag+1, :)), it_) = y2(nonzeros(M_.lead_lag_incidence(M_.maximum_endo_lag+1, :)));
         end
     elseif M_.block_structure.block(blk).Simulation_Type == 3 || ... % solveForwardSimple
diff --git a/matlab/resid.m b/matlab/resid.m
index 46d876053c9e803476933778e6ce86861e64dbac..bee538510d4087ac4b7f8c3c91d35812cb066cb5 100644
--- a/matlab/resid.m
+++ b/matlab/resid.m
@@ -71,11 +71,16 @@ 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, var_indx] = feval([M_.fname '.static'],...
-                                        i,...
-                                        oo_.steady_state,...
-                                        [oo_.exo_steady_state; ...
-                                         oo_.exo_det_steady_state], M_.params, T);
+        [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
diff --git a/matlab/solve_one_boundary.m b/matlab/solve_one_boundary.m
index 0b3530b1ae5705dc97f584fe4063a7a7d7f4374f..af9b6559254036cb66925e1816dbea40a5c4549e 100644
--- a/matlab/solve_one_boundary.m
+++ b/matlab/solve_one_boundary.m
@@ -92,9 +92,9 @@ for it_=start:incr:finish
     g1=spalloc( Blck_size, Blck_size, nze);
     while ~(cvg==1 || iter>maxit_)
         if is_dynamic
-            [r, T(:, it_), g1] = feval(fname, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_, false);
+            [r, ~, T(:, it_), g1] = feval(fname, Block_Num, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_, false);
         else
-            [r, T, g1] = feval(fname, y, x, params, T);
+            [r, ~, T, g1] = feval(fname, Block_Num, y, x, params, T);
         end
         if ~isreal(r)
             max_res=(-(max(max(abs(r))))^2)^0.5;
@@ -203,9 +203,9 @@ for it_=start:incr:finish
                 p = -g1\r ;
                 [ya,f,r,check]=lnsrch1(ya,f,g,p,stpmax, ...
                                        'lnsrch1_wrapper_one_boundary',nn, ...
-                                       y_index_eq, options.solve_tolx, M.lead_lag_incidence(M.maximum_endo_lag+1, :), fname, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_);
+                                       y_index_eq, options.solve_tolx, M.lead_lag_incidence(M.maximum_endo_lag+1, :), fname, Block_Num, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_);
                 %% Recompute temporary terms, since they are not given as output of lnsrch1
-                [~, T(:, it_)] = feval(fname, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_, false);
+                [~, ~, T(:, it_)] = feval(fname, Block_Num, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_, false);
                 dx = ya' - y(index_eq, it_);
                 y(index_eq, it_) = ya;
             elseif (is_dynamic && (stack_solve_algo==1 || stack_solve_algo==0)) || (~is_dynamic && options.solve_algo==6)
@@ -262,10 +262,10 @@ for it_=start:incr:finish
                         y(y_index_eq) = phat;
                     end
                     if is_dynamic
-                        [r, T(:, it_), g1] = feval(fname, dynvars_from_endo_simul(y, it_, M), x, params, ...
+                        [r, ~, T(:, it_), g1] = feval(fname, Block_Num, dynvars_from_endo_simul(y, it_, M), x, params, ...
                                                    steady_state, T(:, it_), it_, false);
                     else
-                        [r, T, g1] = feval(fname, y, x, params, T);
+                        [r, ~, T, g1] = feval(fname, Block_Num, y, x, params, T);
                     end
                     if max(abs(r))>=options.solve_tolf
                         [dx,flag1] = bicgstab(g1,-r,1e-7,Blck_size,L1,U1);
diff --git a/matlab/solve_two_boundaries.m b/matlab/solve_two_boundaries.m
index c46ac5c2273a3b5143ec26261c3b53a27d0ba8cb..d1c595f6b6e21d6f117d51dbd9db144fdf7e9995 100644
--- a/matlab/solve_two_boundaries.m
+++ b/matlab/solve_two_boundaries.m
@@ -83,7 +83,7 @@ while ~(cvg==1 || iter>maxit_)
     r = NaN(Blck_size, periods);
     g1a = spalloc(Blck_size*periods, Blck_size*periods, nze*periods);
     for it_ = y_kmin+(1:periods)
-        [r(:, it_-y_kmin), T(:, it_), g1]=feval(fname, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_, false);
+        [r(:, it_-y_kmin), ~, T(:, it_), g1]=feval(fname, Block_Num, dynvars_from_endo_simul(y, it_, M), x, params, steady_state, T(:, it_), it_, false);
         if periods == 1
             g1a = g1(:, Blck_size+(1:Blck_size));
         elseif it_ == y_kmin+1
@@ -314,7 +314,7 @@ while ~(cvg==1 || iter>maxit_)
             g = (ra'*g1a)';
             f = 0.5*ra'*ra;
             p = -g1a\ra;
-            [yn,f,ra,check]=lnsrch1(ya,f,g,p,stpmax,'lnsrch1_wrapper_two_boundaries',nn,nn, options.solve_tolx, fname, y, y_index,x, params, steady_state, T, periods, Blck_size, M);
+            [yn,f,ra,check]=lnsrch1(ya,f,g,p,stpmax,'lnsrch1_wrapper_two_boundaries',nn,nn, options.solve_tolx, fname, Block_Num, y, y_index,x, params, steady_state, T, periods, Blck_size, M);
             dx = ya - yn;
             y(y_index, y_kmin+(1:periods))=reshape(yn',length(y_index),periods);
         end
diff --git a/preprocessor b/preprocessor
index f4d2ce70dafd1331791b2fd96f3468b3f6c103da..f098329c74225d68fe84f2a5aa32721c2b76036c 160000
--- a/preprocessor
+++ b/preprocessor
@@ -1 +1 @@
-Subproject commit f4d2ce70dafd1331791b2fd96f3468b3f6c103da
+Subproject commit f098329c74225d68fe84f2a5aa32721c2b76036c