diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh
index 7d77e34419740e70fc147f09d5fdcfbfbd726a0f..a718f74741e66823e0af31b78fd82230e2a7b1e3 100644
--- a/src/DynamicModel.hh
+++ b/src/DynamicModel.hh
@@ -884,20 +884,17 @@ DynamicModel::writeParamsDerivativesFile(const string& basename) const
              << "function dynamic_params_derivs(y, x, params, steady_state, it_,"
              << "ss_param_deriv, ss_param_2nd_deriv)" << endl
              << "@inbounds begin" << endl
-             << tt_output.str() << "rp = zeros(" << equations.size() << ", "
+	     << "T = zeros(" << params_derivs_temporary_terms_idxs.size() << ")"
+	     << endl
+             << tt_output.str()
+             << "rp = zeros(" << equations.size() << ", "
              << symbol_table.param_nbr() << ");" << endl
-             << rp_output.str() << "gp = zeros(" << equations.size() << ", "
-             << getJacobianColsNbr(false) << ", " << symbol_table.param_nbr() << ");" << endl
-             << gp_output.str() << "rpp = zeros(" << params_derivatives.at({0, 2}).size() << ",4);"
-             << endl
-             << rpp_output.str() << "gpp = zeros(" << params_derivatives.at({1, 2}).size() << ",5);"
-             << endl
-             << gpp_output.str() << "hp = zeros(" << params_derivatives.at({2, 1}).size() << ",5);"
-             << endl
-             << hp_output.str() << "g3p = zeros(" << params_derivatives.at({3, 1}).size() << ",6);"
-             << endl
-             << g3p_output.str() << "end" << endl
-             << "return (rp, gp, rpp, gpp, hp, g3p)" << endl
+             << rp_output.str()
+             << "gp = zeros(" << equations.size() << ", " << getJacobianColsNbr(false)
+	     << ", " << symbol_table.param_nbr() << ");" << endl
+             << gp_output.str()
+             << "end" << endl
+             << "return (rp, gp)" << endl
              << "end" << endl;
 
       writeToFileIfModified(output, filesystem::path {basename} / "model" / "julia"
diff --git a/src/StaticModel.hh b/src/StaticModel.hh
index 288c6e4725f9485cece581d2d7d081bf0390b547..b75759b9ba9afc95f2993a8356281909ff13104f 100644
--- a/src/StaticModel.hh
+++ b/src/StaticModel.hh
@@ -340,18 +340,16 @@ StaticModel::writeParamsDerivativesFile(const string& basename) const
              << "#" << endl
              << "function static_params_derivs(y, x, params)" << endl
              << "@inbounds begin" << endl
-             << tt_output.str() << "rp = zeros(" << equations.size() << ", "
+	     << "T = zeros(" << params_derivs_temporary_terms_idxs.size() << ")" << endl
+             << tt_output.str()
+             << "rp = zeros(" << equations.size() << ", "
              << symbol_table.param_nbr() << ");" << endl
-             << rp_output.str() << "gp = zeros(" << equations.size() << ", "
-             << symbol_table.endo_nbr() << ", " << symbol_table.param_nbr() << ");" << endl
-             << gp_output.str() << "rpp = zeros(" << params_derivatives.at({0, 2}).size() << ",4);"
-             << endl
-             << rpp_output.str() << "gpp = zeros(" << params_derivatives.at({1, 2}).size() << ",5);"
-             << endl
-             << gpp_output.str() << "hp = zeros(" << params_derivatives.at({2, 1}).size() << ",5);"
-             << endl
-             << hp_output.str() << "end" << endl
-             << "return (rp, gp, rpp, gpp, hp)" << endl
+             << rp_output.str()
+             << "gp = zeros(" << equations.size() << ", " << symbol_table.endo_nbr() << ", "
+             << symbol_table.param_nbr() << ");" << endl
+             << gp_output.str()
+             << "end" << endl
+             << "return (rp, gp)" << endl
              << "end" << endl;
 
       writeToFileIfModified(output, filesystem::path {basename} / "model" / "julia"