diff --git a/mex/sources/bytecode/Interpreter.cc b/mex/sources/bytecode/Interpreter.cc
index 3e0c2bc782bf586f3d832c32a03be2d953971ac4..88b1232d487707bc448fca86533bf78816b042f7 100644
--- a/mex/sources/bytecode/Interpreter.cc
+++ b/mex/sources/bytecode/Interpreter.cc
@@ -19,7 +19,6 @@
 
 #include <sstream>
 #include <algorithm>
-#include <cstring>
 #include <filesystem>
 #include <numeric>
 #include <cfenv>
@@ -31,7 +30,7 @@ constexpr double BIG = 1.0e+8, SMALL = 1.0e-5;
 Interpreter::Interpreter(Evaluate &evaluator_arg, double *params_arg, double *y_arg, double *ya_arg, double *x_arg, double *steady_y_arg,
                          double *direction_arg, size_t y_size_arg,
                          size_t nb_row_x_arg, int periods_arg, int y_kmin_arg, int y_kmax_arg,
-                         int maxit_arg_, double solve_tolf_arg, size_t size_of_direction_arg, int y_decal_arg, double markowitz_c_arg,
+                         int maxit_arg_, double solve_tolf_arg, int y_decal_arg, double markowitz_c_arg,
                          string &filename_arg, int minimal_solving_periods_arg, int stack_solve_algo_arg, int solve_algo_arg,
                          bool global_temporary_terms_arg, bool print_arg, bool print_error_arg, mxArray *GlobalTemporaryTerms_arg,
                          bool steady_state_arg, bool block_decomposed_arg, bool print_it_arg, int col_x_arg, int col_y_arg, const BasicSymbolTable &symbol_table_arg)
@@ -47,7 +46,6 @@ Interpreter::Interpreter(Evaluate &evaluator_arg, double *params_arg, double *y_
   periods = periods_arg;
   maxit_ = maxit_arg_;
   solve_tolf = solve_tolf_arg;
-  size_of_direction = size_of_direction_arg;
   slowc = 1;
   slowc_save = 1;
   y_decal = y_decal_arg;
@@ -487,7 +485,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
       mxFree(u);
       mxFree(index_equa);
       mxFree(index_vara);
-      memset(direction, 0, size_of_direction);
+      fill_n(direction, y_size*col_y, 0);
       End_Solver();
       break;
     case BlockSimulationType::solveBackwardComplete:
@@ -508,7 +506,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
 
       mxFree(index_equa);
       mxFree(index_vara);
-      memset(direction, 0, size_of_direction);
+      fill_n(direction, y_size*col_y, 0);
       mxFree(u);
       End_Solver();
       break;
@@ -605,7 +603,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
         mxFree(index_equa);
       if (res)
         mxFree(res);
-      memset(direction, 0, size_of_direction);
+      fill_n(direction, y_size*col_y, 0);
       End_Solver();
       break;
     default:
diff --git a/mex/sources/bytecode/Interpreter.hh b/mex/sources/bytecode/Interpreter.hh
index 528d4160e4642246fb617b86a29221b7fa03fa87..9db837a3f894abe2acbc348dd1cd96289f8759de 100644
--- a/mex/sources/bytecode/Interpreter.hh
+++ b/mex/sources/bytecode/Interpreter.hh
@@ -37,7 +37,6 @@ class Interpreter : public dynSparseMatrix
 {
 private:
   vector<int> previous_block_exogenous;
-  int size_of_direction;
   bool global_temporary_terms;
   bool print;
   int col_x, col_y;
@@ -54,7 +53,7 @@ public:
   Interpreter(Evaluate &evaluator_arg, double *params_arg, double *y_arg, double *ya_arg, double *x_arg, double *steady_y_arg,
               double *direction_arg, size_t y_size_arg,
               size_t nb_row_x_arg, int periods_arg, int y_kmin_arg, int y_kmax_arg,
-              int maxit_arg_, double solve_tolf_arg, size_t size_of_direction_arg, int y_decal_arg, double markowitz_c_arg,
+              int maxit_arg_, double solve_tolf_arg, int y_decal_arg, double markowitz_c_arg,
               string &filename_arg, int minimal_solving_periods_arg, int stack_solve_algo_arg, int solve_algo_arg,
               bool global_temporary_terms_arg, bool print_arg, bool print_error_arg, mxArray *GlobalTemporaryTerms_arg,
               bool steady_state_arg, bool block_decomposed_arg, bool print_it_arg, int col_x_arg, int col_y_arg, const BasicSymbolTable &symbol_table_arg);
diff --git a/mex/sources/bytecode/bytecode.cc b/mex/sources/bytecode/bytecode.cc
index 97156848ac0b7db6ed4356e44a6079b33dca8326..bc1f768de38478129d52cdb2bf32b16e62b43a34 100644
--- a/mex/sources/bytecode/bytecode.cc
+++ b/mex/sources/bytecode/bytecode.cc
@@ -19,8 +19,8 @@
 
 #include <ctime>
 #include <cmath>
-#include <cstring>
 #include <type_traits>
+#include <algorithm>
 
 #include "Interpreter.hh"
 #include "ErrorHandling.hh"
@@ -702,18 +702,13 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
   test_mxMalloc(ya, __LINE__, __FILE__, __func__, size_of_direction);
   direction = static_cast<double *>(mxMalloc(size_of_direction));
   test_mxMalloc(direction, __LINE__, __FILE__, __func__, size_of_direction);
-  memset(direction, 0, size_of_direction);
   auto *x = static_cast<double *>(mxMalloc(col_x*row_x*sizeof(double)));
   test_mxMalloc(x, __LINE__, __FILE__, __func__, col_x*row_x*sizeof(double));
-  for (i = 0; i < row_x*col_x; i++)
-    x[i] = static_cast<double>(xd[i]);
-  for (i = 0; i < row_y*col_y; i++)
-    {
-      y[i] = static_cast<double>(yd[i]);
-      ya[i] = static_cast<double>(yd[i]);
-    }
-  size_t y_size = row_y;
-  size_t nb_row_x = row_x;
+
+  fill_n(direction, row_y*col_y, 0);
+  copy_n(xd, row_x*col_x, x);
+  copy_n(yd, row_y*col_y, y);
+  copy_n(yd, row_y*col_y, ya);
 
   clock_t t0 = clock();
 
@@ -721,8 +716,8 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
     + (steady_state ? "static" : "dynamic") + ".cod"};
   Evaluate evaluator {codfile, steady_state, symbol_table};
 
-  Interpreter interprete {evaluator, params, y, ya, x, steady_yd, direction, y_size, nb_row_x,
-                          periods, y_kmin, y_kmax, maxit_, solve_tolf, size_of_direction, y_decal,
+  Interpreter interprete {evaluator, params, y, ya, x, steady_yd, direction, row_y, row_x,
+                          periods, y_kmin, y_kmax, maxit_, solve_tolf, y_decal,
                           markowitz_c, file_name, minimal_solving_periods, stack_solve_algo,
                           solve_algo, global_temporary_terms, print, print_error, GlobalTemporaryTerms,
                           steady_state, block_decomposed, print_it, col_x, col_y, symbol_table};
@@ -730,31 +725,18 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
   bool r;
   vector<int> blocks;
 
-  if (extended_path)
+  try
     {
-      try
-        {
-          tie(r, blocks) = interprete.extended_path(file_name, evaluate, block, max_periods, sextended_path, sconditional_extended_path, dates, table_conditional_global);
-        }
-      catch (GeneralException &feh)
-        {
-          // Release the lock on dynamic.bin for MATLAB+Windows, see #1815
-          interprete.Close_SaveCode();
-          mexErrMsgTxt(feh.message.c_str());
-        }
+      if (extended_path)
+        tie(r, blocks) = interprete.extended_path(file_name, evaluate, block, max_periods, sextended_path, sconditional_extended_path, dates, table_conditional_global);
+      else
+        tie(r, blocks) = interprete.compute_blocks(file_name, evaluate, block);
     }
-  else
+  catch (GeneralException &feh)
     {
-      try
-        {
-          tie(r, blocks) = interprete.compute_blocks(file_name, evaluate, block);
-        }
-      catch (GeneralException &feh)
-        {
-          // Release the lock on dynamic.bin for MATLAB+Windows, see #1815
-          interprete.Close_SaveCode();
-          mexErrMsgTxt(feh.message.c_str());
-        }
+      // Release the lock on dynamic.bin for MATLAB+Windows, see #1815
+      interprete.Close_SaveCode();
+      mexErrMsgTxt(feh.message.c_str());
     }
 
   clock_t t1 = clock();