diff --git a/mex/sources/bytecode/BasicSymbolTable.cc b/mex/sources/bytecode/BasicSymbolTable.cc
index c41f98a62dce99595346e1f37b5b7daf163197d3..5d51b9008b830d5ef4ca7e8071c105c2e325f08a 100644
--- a/mex/sources/bytecode/BasicSymbolTable.cc
+++ b/mex/sources/bytecode/BasicSymbolTable.cc
@@ -21,10 +21,9 @@
 
 #include "dynmex.h"
 
-BasicSymbolTable::BasicSymbolTable(const mxArray *M_)
+BasicSymbolTable::BasicSymbolTable(const mxArray* M_)
 {
-  auto get_field_names = [&](const char *field_name, SymbolType type)
-  {
+  auto get_field_names = [&](const char* field_name, SymbolType type) {
     vector<string> r;
     if (mxGetFieldNumber(M_, field_name) != -1)
       {
@@ -33,16 +32,17 @@ BasicSymbolTable::BasicSymbolTable(const mxArray *M_)
           mexErrMsgTxt(("M_."s + field_name + " is not a cell array").c_str());
         for (size_t i {0}; i < mxGetNumberOfElements(M_field); i++)
           {
-            const mxArray *cell_mx = mxGetCell(M_field, i);
+            const mxArray* cell_mx = mxGetCell(M_field, i);
             if (!(cell_mx && mxIsChar(cell_mx)))
-              mexErrMsgTxt(("M_."s + field_name + " contains a cell which is not a character array").c_str());
+              mexErrMsgTxt(("M_."s + field_name + " contains a cell which is not a character array")
+                               .c_str());
             r.emplace_back(mxArrayToString(cell_mx));
           }
       }
 
     // Fill the reverse map
     for (size_t i {0}; i < r.size(); i++)
-      name_to_id_and_type.emplace(r[i], pair{type, i});
+      name_to_id_and_type.emplace(r[i], pair {type, i});
 
     return r;
   };
@@ -71,21 +71,23 @@ BasicSymbolTable::getName(SymbolType type, int tsid) const
           mexErrMsgTxt(("Unsupported symbol type: " + to_string(static_cast<int>(type))).c_str());
         }
     }
-  catch (out_of_range &)
+  catch (out_of_range&)
     {
-      mexErrMsgTxt(("Unknown symbol with ID " + to_string(tsid) + " and type " + to_string(static_cast<int>(type))).c_str());
+      mexErrMsgTxt(("Unknown symbol with ID " + to_string(tsid) + " and type "
+                    + to_string(static_cast<int>(type)))
+                       .c_str());
     }
   __builtin_unreachable(); // Silence GCC warning
 }
 
 pair<SymbolType, int>
-BasicSymbolTable::getIDAndType(const string &name) const
+BasicSymbolTable::getIDAndType(const string& name) const
 {
   try
     {
       return name_to_id_and_type.at(name);
     }
-  catch (out_of_range &)
+  catch (out_of_range&)
     {
       mexErrMsgTxt(("Unknown symbol: " + name).c_str());
     }
@@ -96,7 +98,7 @@ size_t
 BasicSymbolTable::maxEndoNameLength() const
 {
   size_t r {0};
-  for (const auto &n : endo_names)
+  for (const auto& n : endo_names)
     r = max(r, n.size());
   return r;
 }
diff --git a/mex/sources/bytecode/BasicSymbolTable.hh b/mex/sources/bytecode/BasicSymbolTable.hh
index 9a2f5a9a799475d50ee8f70ac50491e62759b036..013df0bb23371c04f94e713984444f7ae4bdce7f 100644
--- a/mex/sources/bytecode/BasicSymbolTable.hh
+++ b/mex/sources/bytecode/BasicSymbolTable.hh
@@ -20,10 +20,10 @@
 #ifndef _BASIC_SYMBOL_TABLE_HH
 #define _BASIC_SYMBOL_TABLE_HH
 
-#include <string>
-#include <vector>
 #include <map>
+#include <string>
 #include <utility>
+#include <vector>
 
 #include "dynmex.h"
 
@@ -34,10 +34,11 @@ using namespace std;
 class BasicSymbolTable
 {
 public:
-  BasicSymbolTable(const mxArray *M_);
+  BasicSymbolTable(const mxArray* M_);
   string getName(SymbolType type, int tsid) const;
-  pair<SymbolType, int> getIDAndType(const string &name) const;
+  pair<SymbolType, int> getIDAndType(const string& name) const;
   size_t maxEndoNameLength() const;
+
 private:
   vector<string> endo_names, param_names, exo_names, exo_det_names;
   map<string, pair<SymbolType, int>> name_to_id_and_type;
diff --git a/mex/sources/bytecode/ErrorHandling.hh b/mex/sources/bytecode/ErrorHandling.hh
index 99f84729545878464955c7da956951154646ba87..49ec933eb260c317bcfa83a4929741506c8f834d 100644
--- a/mex/sources/bytecode/ErrorHandling.hh
+++ b/mex/sources/bytecode/ErrorHandling.hh
@@ -20,9 +20,9 @@
 #ifndef _ERROR_HANDLING_HH
 #define _ERROR_HANDLING_HH
 
-#include <string>
-#include <sstream>
 #include <cmath>
+#include <sstream>
+#include <string>
 
 using namespace std;
 
@@ -34,23 +34,22 @@ struct GeneralException
 struct FloatingPointException : public GeneralException
 {
   const string location;
-  FloatingPointException(const string &details, string location_arg) :
-    GeneralException {"Floating point error: " + details},
-    location {move(location_arg)}
+  FloatingPointException(const string& details, string location_arg) :
+      GeneralException {"Floating point error: " + details}, location {move(location_arg)}
   {
   }
 };
 
 struct UnaryOpException : public FloatingPointException
 {
-  UnaryOpException(const string &op, double value, string location_arg) :
-    FloatingPointException { [=]
-    {
-      // We don’t use std::to_string(), because it uses fixed formatting
-      ostringstream s;
-      s << op << "(X) with X=" << defaultfloat << value;
-      return s.str();
-    }(), move(location_arg) }
+  UnaryOpException(const string& op, double value, string location_arg) :
+      FloatingPointException {[=] {
+                                // We don’t use std::to_string(), because it uses fixed formatting
+                                ostringstream s;
+                                s << op << "(X) with X=" << defaultfloat << value;
+                                return s.str();
+                              }(),
+                              move(location_arg)}
   {
   }
 };
@@ -58,13 +57,13 @@ struct UnaryOpException : public FloatingPointException
 struct DivideException : public FloatingPointException
 {
   DivideException(double v1, double v2, string location_arg) :
-    FloatingPointException { [=]
-    {
-      // We don’t use std::to_string(), because it uses fixed formatting
-      ostringstream s;
-      s << "a/X with a=" << defaultfloat << v1 << " and X= " << v2;
-      return s.str();
-    }(), move(location_arg) }
+      FloatingPointException {[=] {
+                                // We don’t use std::to_string(), because it uses fixed formatting
+                                ostringstream s;
+                                s << "a/X with a=" << defaultfloat << v1 << " and X= " << v2;
+                                return s.str();
+                              }(),
+                              move(location_arg)}
   {
   }
 };
@@ -72,15 +71,15 @@ struct DivideException : public FloatingPointException
 struct PowException : public FloatingPointException
 {
   PowException(double base, double exponent, string location_arg) :
-    FloatingPointException { [=]
-    {
-      // We don’t use std::to_string(), because it uses fixed formatting
-      ostringstream s;
-      s << "X^a with X=" << defaultfloat << base;
-      if (fabs(base) <= 1e-10)
-        s << " and a=" << exponent;
-      return s.str();
-    }(), move(location_arg) }
+      FloatingPointException {[=] {
+                                // We don’t use std::to_string(), because it uses fixed formatting
+                                ostringstream s;
+                                s << "X^a with X=" << defaultfloat << base;
+                                if (fabs(base) <= 1e-10)
+                                  s << " and a=" << exponent;
+                                return s.str();
+                              }(),
+                              move(location_arg)}
   {
   }
 };
@@ -94,17 +93,18 @@ struct UserException : public GeneralException
 
 struct FatalException : public GeneralException
 {
-  FatalException(const string &details) :
-    GeneralException {"Fatal error: " + details}
+  FatalException(const string& details) : GeneralException {"Fatal error: " + details}
   {
   }
 };
 
 inline void
-test_mxMalloc(void *z, int line, const string &file, const string &func, int amount)
+test_mxMalloc(void* z, int line, const string& file, const string& func, int amount)
 {
   if (!z && amount > 0)
-    throw FatalException{"mxMalloc: out of memory " + to_string(amount) + " bytes required at line " + to_string(line) + " in function " + func + " (file " + file};
+    throw FatalException {"mxMalloc: out of memory " + to_string(amount)
+                          + " bytes required at line " + to_string(line) + " in function " + func
+                          + " (file " + file};
 }
 
 #ifdef MATLAB_MEX_FILE
diff --git a/mex/sources/bytecode/Evaluate.cc b/mex/sources/bytecode/Evaluate.cc
index 041c9b165cf6be3cf271bbc28c961e1ed71c8f20..1adf1cf5faacce227a11da0daa29a8ed6543306f 100644
--- a/mex/sources/bytecode/Evaluate.cc
+++ b/mex/sources/bytecode/Evaluate.cc
@@ -17,22 +17,23 @@
  * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#include <sstream>
+#include <cfenv>
 #include <cmath>
 #include <limits>
-#include <stack>
-#include <cfenv>
 #include <numbers>
+#include <sstream>
+#include <stack>
 
 #include <dynmex.h>
 
-#include "Evaluate.hh"
 #include "CommonEnums.hh"
 #include "ErrorHandling.hh"
+#include "Evaluate.hh"
 
-Evaluate::Evaluate(const filesystem::path &codfile, bool steady_state_arg, const BasicSymbolTable &symbol_table_arg) :
-  symbol_table {symbol_table_arg},
-  steady_state {steady_state_arg}
+Evaluate::Evaluate(const filesystem::path& codfile, bool steady_state_arg,
+                   const BasicSymbolTable& symbol_table_arg) :
+    symbol_table {symbol_table_arg},
+    steady_state {steady_state_arg}
 {
   ifstream CompiledCode {codfile, ios::in | ios::binary | ios::ate};
   if (!CompiledCode.is_open())
@@ -47,250 +48,251 @@ Evaluate::Evaluate(const filesystem::path &codfile, bool steady_state_arg, const
   bool done {false};
   while (!done)
     {
-      BytecodeInstruction *instr {reinterpret_cast<BytecodeInstruction *>(code)};
-      switch (*reinterpret_cast<Tags *>(code))
+      BytecodeInstruction* instr {reinterpret_cast<BytecodeInstruction*>(code)};
+      switch (*reinterpret_cast<Tags*>(code))
         {
         case Tags::FLDZ:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FLDZ\n");
-# endif
+#endif
           code += sizeof(FLDZ_);
           break;
         case Tags::FEND:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FEND\n");
-# endif
+#endif
           code += sizeof(FEND_);
           done = true;
           break;
         case Tags::FENDBLOCK:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FENDBLOCK\n");
-# endif
+#endif
           code += sizeof(FENDBLOCK_);
           break;
         case Tags::FENDEQU:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FENDEQU\n");
-# endif
+#endif
           code += sizeof(FENDEQU_);
           break;
         case Tags::FDIMT:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FDIMT\n");
-# endif
+#endif
           code += sizeof(FDIMT_);
           break;
         case Tags::FDIMST:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FDIMST\n");
-# endif
+#endif
           code += sizeof(FDIMST_);
           break;
         case Tags::FNUMEXPR:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FNUMEXPR\n");
-# endif
+#endif
           code += sizeof(FNUMEXPR_);
           break;
         case Tags::FLDC:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FLDC\n");
-# endif
+#endif
           code += sizeof(FLDC_);
           break;
         case Tags::FLDU:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FLDU\n");
-# endif
+#endif
           code += sizeof(FLDU_);
           break;
         case Tags::FLDSU:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FLDSU\n");
-# endif
+#endif
           code += sizeof(FLDSU_);
           break;
         case Tags::FLDR:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FLDR\n");
-# endif
+#endif
           code += sizeof(FLDR_);
           break;
         case Tags::FLDT:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FLDT\n");
-# endif
+#endif
           code += sizeof(FLDT_);
           break;
         case Tags::FLDST:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FLDST\n");
-# endif
+#endif
           code += sizeof(FLDST_);
           break;
         case Tags::FSTPT:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FSTPT\n");
-# endif
+#endif
           code += sizeof(FSTPT_);
           break;
         case Tags::FSTPST:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FSTPST\n");
-# endif
+#endif
           code += sizeof(FSTPST_);
           break;
         case Tags::FSTPR:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FSTPR\n");
-# endif
+#endif
           code += sizeof(FSTPR_);
           break;
         case Tags::FSTPU:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FSTPU\n");
-# endif
+#endif
           code += sizeof(FSTPU_);
           break;
         case Tags::FSTPSU:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FSTPSU\n");
-# endif
+#endif
           code += sizeof(FSTPSU_);
           break;
         case Tags::FSTPG:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FSTPG\n");
-# endif
+#endif
           code += sizeof(FSTPG_);
           break;
         case Tags::FSTPG2:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FSTPG2\n");
-# endif
+#endif
           code += sizeof(FSTPG2_);
           break;
         case Tags::FSTPG3:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FSTPG3\n");
-# endif
+#endif
           code += sizeof(FSTPG3_);
           break;
         case Tags::FUNARY:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FUNARY\n");
-# endif
+#endif
           code += sizeof(FUNARY_);
           break;
         case Tags::FBINARY:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FBINARY\n");
-# endif
+#endif
           code += sizeof(FBINARY_);
           break;
         case Tags::FTRINARY:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FTRINARY\n");
-# endif
+#endif
           code += sizeof(FTRINARY_);
           break;
         case Tags::FLDVS:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FLDVS\n");
-# endif
+#endif
           code += sizeof(FLDVS_);
           break;
         case Tags::FLDSV:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FLDSV\n");
-# endif
+#endif
           code += sizeof(FLDSV_);
           break;
         case Tags::FSTPSV:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FSTPSV\n");
-# endif
+#endif
           code += sizeof(FSTPSV_);
           break;
         case Tags::FLDV:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FLDV\n");
-# endif
+#endif
           code += sizeof(FLDV_);
           break;
         case Tags::FSTPV:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FSTPV\n");
-# endif
+#endif
           code += sizeof(FSTPV_);
           break;
         case Tags::FBEGINBLOCK:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FBEGINBLOCK\n");
-# endif
+#endif
           deserialized_fbeginblock.emplace_back(code);
           begin_block.push_back(instructions_list.size());
           nb_blocks++;
           instr = &deserialized_fbeginblock.back();
           break;
         case Tags::FJMPIFEVAL:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FJMPIFEVAL\n");
-# endif
+#endif
           code += sizeof(FJMPIFEVAL_);
           break;
         case Tags::FJMP:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FJMP\n");
-# endif
+#endif
           code += sizeof(FJMP_);
           break;
         case Tags::FCALL:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FCALL\n");
-# endif
+#endif
           deserialized_fcall.emplace_back(code);
           instr = &deserialized_fcall.back();
           break;
         case Tags::FLDTEF:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FLDTEF\n");
-# endif
+#endif
           code += sizeof(FLDTEF_);
           break;
         case Tags::FSTPTEF:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FSTPTEF\n");
-# endif
+#endif
           code += sizeof(FSTPTEF_);
           break;
         case Tags::FLDTEFD:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FLDTEFD\n");
-# endif
+#endif
           code += sizeof(FLDTEFD_);
           break;
         case Tags::FSTPTEFD:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FSTPTEFD\n");
-# endif
+#endif
           code += sizeof(FSTPTEFD_);
           break;
         case Tags::FLDTEFDD:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FLDTEFDD\n");
-# endif
+#endif
           code += sizeof(FLDTEFDD_);
           break;
         case Tags::FSTPTEFDD:
-# ifdef DEBUGL
+#ifdef DEBUGL
           mexPrintf("FSTPTEFDD\n");
-# endif
+#endif
           code += sizeof(FSTPTEFDD_);
           break;
         default:
-          throw FatalException {"Unknown tag value=" + to_string(static_cast<int>(*reinterpret_cast<Tags *>(code)))};
+          throw FatalException {"Unknown tag value="
+                                + to_string(static_cast<int>(*reinterpret_cast<Tags*>(code)))};
         }
       instructions_list.push_back(instr);
     }
@@ -314,22 +316,25 @@ Evaluate::error_location(it_code_type expr_begin, it_code_type faulty_op, int it
       Error_loc << "first order derivative of equation";
       break;
     }
-  Error_loc << " " << EQN_equation+1;
+  Error_loc << " " << EQN_equation + 1;
   if (nb_blocks > 1)
-    Error_loc << " in block " << block_num+1;
+    Error_loc << " in block " << block_num + 1;
   switch (EQN_type)
     {
     case ExpressionType::TemporaryTerm:
     case ExpressionType::ModelEquation:
       break;
     case ExpressionType::FirstEndoDerivative:
-      Error_loc << " with respect to endogenous variable " << symbol_table.getName(SymbolType::endogenous, EQN_dvar1);
+      Error_loc << " with respect to endogenous variable "
+                << symbol_table.getName(SymbolType::endogenous, EQN_dvar1);
       break;
     case ExpressionType::FirstExoDerivative:
-      Error_loc << " with respect to exogenous variable " << symbol_table.getName(SymbolType::exogenous, EQN_dvar1);
+      Error_loc << " with respect to exogenous variable "
+                << symbol_table.getName(SymbolType::exogenous, EQN_dvar1);
       break;
     case ExpressionType::FirstExodetDerivative:
-      Error_loc << " with respect to deterministic exogenous variable " << symbol_table.getName(SymbolType::exogenousDet, EQN_dvar1);
+      Error_loc << " with respect to deterministic exogenous variable "
+                << symbol_table.getName(SymbolType::exogenousDet, EQN_dvar1);
       break;
     }
   if (!steady_state)
@@ -339,8 +344,7 @@ Evaluate::error_location(it_code_type expr_begin, it_code_type faulty_op, int it
      (materialized by an operator between braces), returns a string spanning two
      lines, the first line containing the original string without the braces,
      the second line containing tildes (~) under the faulty operator. */
-  auto add_underscore_to_fpe = [](const string &str)
-  {
+  auto add_underscore_to_fpe = [](const string& str) {
     string line1;
     optional<size_t> pos1, pos2;
     string line2(str.length(), ' ');
@@ -356,7 +360,7 @@ Evaluate::error_location(it_code_type expr_begin, it_code_type faulty_op, int it
               pos2 = line1.length();
             if (pos1 && pos2)
               {
-                line2.replace(*pos1, *pos2-*pos1, *pos2-*pos1, '~');
+                line2.replace(*pos1, *pos2 - *pos1, *pos2 - *pos1, '~');
                 pos1.reset();
                 pos2.reset();
               }
@@ -371,7 +375,8 @@ Evaluate::error_location(it_code_type expr_begin, it_code_type faulty_op, int it
 }
 
 pair<string, Evaluate::it_code_type>
-Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optional<it_code_type> &faulty_op) const
+Evaluate::print_expression(const Evaluate::it_code_type& expr_begin,
+                           const optional<it_code_type>& faulty_op) const
 {
   /* First element is output string, 2nd element is precedence of last
      operator, 3rd element is opcode if the last operator was a binary
@@ -389,8 +394,7 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
   ExpressionType equation_type {ExpressionType::ModelEquation};
   ExternalFunctionCallType call_type {ExternalFunctionCallType::levelWithoutDerivative};
 
-  auto lag_to_string = [](int l) -> string
-  {
+  auto lag_to_string = [](int l) -> string {
     if (l > 0)
       return "(+" + to_string(l) + ")";
     else if (l < 0)
@@ -400,9 +404,8 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
   };
 
   // Helper for FST* tags
-  auto assign_lhs = [&](const string &lhs)
-  {
-    auto &[str, prec, opcode] {Stack.top()};
+  auto assign_lhs = [&](const string& lhs) {
+    auto& [str, prec, opcode] {Stack.top()};
     str.insert(0, lhs + " = ");
     prec = 0;
     opcode = BinaryOpcode::equal;
@@ -415,12 +418,12 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
     {
 #ifdef MATLAB_MEX_FILE
       if (utIsInterruptPending())
-        throw UserException{};
+        throw UserException {};
 #endif
       switch ((*it_code)->op_code)
         {
         case Tags::FNUMEXPR:
-          switch (static_cast<FNUMEXPR_ *>(*it_code)->get_expression_type())
+          switch (static_cast<FNUMEXPR_*>(*it_code)->get_expression_type())
             {
             case ExpressionType::TemporaryTerm:
               equation_type = ExpressionType::TemporaryTerm;
@@ -438,17 +441,17 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
               equation_type = ExpressionType::FirstExodetDerivative;
               break;
             default:
-              throw FatalException{"In print_expression, expression type "
-                                   + to_string(static_cast<int>(static_cast<FNUMEXPR_ *>(*it_code)->get_expression_type()))
-                                   + " not implemented yet"};
+              throw FatalException {"In print_expression, expression type "
+                                    + to_string(static_cast<int>(
+                                        static_cast<FNUMEXPR_*>(*it_code)->get_expression_type()))
+                                    + " not implemented yet"};
             }
           break;
         case Tags::FLDV:
           {
-            int var {static_cast<FLDV_ *>(*it_code)->get_pos()};
-            int lag {static_cast<FLDV_ *>(*it_code)->get_lead_lag()};
-            switch (SymbolType type {static_cast<FLDV_ *>(*it_code)->get_type()};
-                    type)
+            int var {static_cast<FLDV_*>(*it_code)->get_pos()};
+            int lag {static_cast<FLDV_*>(*it_code)->get_lead_lag()};
+            switch (SymbolType type {static_cast<FLDV_*>(*it_code)->get_type()}; type)
               {
               case SymbolType::parameter:
               case SymbolType::endogenous:
@@ -457,15 +460,14 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
                 Stack.emplace(symbol_table.getName(type, var) + lag_to_string(lag), 100, nullopt);
                 break;
               default:
-                throw FatalException{"FLDV: Unknown variable type"};
-            }
+                throw FatalException {"FLDV: Unknown variable type"};
+              }
           }
           break;
         case Tags::FLDSV:
           {
-            int var {static_cast<FLDSV_ *>(*it_code)->get_pos()};
-            switch (SymbolType type {static_cast<FLDSV_ *>(*it_code)->get_type()};
-                    type)
+            int var {static_cast<FLDSV_*>(*it_code)->get_pos()};
+            switch (SymbolType type {static_cast<FLDSV_*>(*it_code)->get_type()}; type)
               {
               case SymbolType::parameter:
               case SymbolType::endogenous:
@@ -474,15 +476,14 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
                 Stack.emplace(symbol_table.getName(type, var), 100, nullopt);
                 break;
               default:
-                throw FatalException{"FLDSV: Unknown variable type"};
+                throw FatalException {"FLDSV: Unknown variable type"};
               }
           }
           break;
         case Tags::FLDVS:
           {
-            int var {static_cast<FLDVS_ *>(*it_code)->get_pos()};
-            switch (SymbolType type {static_cast<FLDVS_ *>(*it_code)->get_type()};
-                    type)
+            int var {static_cast<FLDVS_*>(*it_code)->get_pos()};
+            switch (SymbolType type {static_cast<FLDVS_*>(*it_code)->get_type()}; type)
               {
               case SymbolType::parameter:
               case SymbolType::endogenous:
@@ -491,24 +492,29 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
                 Stack.emplace(symbol_table.getName(type, var), 100, nullopt);
                 break;
               default:
-                throw FatalException{"FLDVS: Unknown variable type"};
+                throw FatalException {"FLDVS: Unknown variable type"};
               }
           }
           break;
         case Tags::FLDT:
-          Stack.emplace("T" + to_string(static_cast<FLDT_ *>(*it_code)->get_pos() + 1), 100, nullopt);
+          Stack.emplace("T" + to_string(static_cast<FLDT_*>(*it_code)->get_pos() + 1), 100,
+                        nullopt);
           break;
         case Tags::FLDST:
-          Stack.emplace("T" + to_string(static_cast<FLDST_ *>(*it_code)->get_pos() + 1), 100, nullopt);
+          Stack.emplace("T" + to_string(static_cast<FLDST_*>(*it_code)->get_pos() + 1), 100,
+                        nullopt);
           break;
         case Tags::FLDU:
-          Stack.emplace("u(" + to_string(static_cast<FLDU_ *>(*it_code)->get_pos() + 1) + " + it_)", 100, nullopt);
+          Stack.emplace("u(" + to_string(static_cast<FLDU_*>(*it_code)->get_pos() + 1) + " + it_)",
+                        100, nullopt);
           break;
         case Tags::FLDSU:
-          Stack.emplace("u(" + to_string(static_cast<FLDSU_ *>(*it_code)->get_pos() + 1) + ")", 100, nullopt);
+          Stack.emplace("u(" + to_string(static_cast<FLDSU_*>(*it_code)->get_pos() + 1) + ")", 100,
+                        nullopt);
           break;
         case Tags::FLDR:
-          Stack.emplace("residual(" + to_string(static_cast<FLDR_ *>(*it_code)->get_pos() + 1) + ")", 100, nullopt);
+          Stack.emplace("residual(" + to_string(static_cast<FLDR_*>(*it_code)->get_pos() + 1) + ")",
+                        100, nullopt);
           break;
         case Tags::FLDZ:
           Stack.emplace("0", 100, nullopt);
@@ -517,16 +523,15 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
           {
             // We don’t use std::to_string(), because it uses fixed formatting
             ostringstream s;
-            s << defaultfloat << static_cast<FLDC_ *>(*it_code)->get_value();
+            s << defaultfloat << static_cast<FLDC_*>(*it_code)->get_value();
             Stack.emplace(s.str(), 100, nullopt);
           }
           break;
         case Tags::FSTPV:
           {
-            int var {static_cast<FSTPV_ *>(*it_code)->get_pos()};
-            int lag {static_cast<FSTPV_ *>(*it_code)->get_lead_lag()};
-            switch (SymbolType type {static_cast<FSTPV_ *>(*it_code)->get_type()};
-                    type)
+            int var {static_cast<FSTPV_*>(*it_code)->get_pos()};
+            int lag {static_cast<FSTPV_*>(*it_code)->get_lead_lag()};
+            switch (SymbolType type {static_cast<FSTPV_*>(*it_code)->get_type()}; type)
               {
               case SymbolType::parameter:
               case SymbolType::endogenous:
@@ -535,15 +540,14 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
                 assign_lhs(symbol_table.getName(type, var) + lag_to_string(lag));
                 break;
               default:
-                throw FatalException{"FSTPV: Unknown variable type"};
+                throw FatalException {"FSTPV: Unknown variable type"};
               }
           }
           break;
         case Tags::FSTPSV:
           {
-            int var {static_cast<FSTPSV_ *>(*it_code)->get_pos()};
-            switch (SymbolType type {static_cast<FSTPSV_ *>(*it_code)->get_type()};
-                    type)
+            int var {static_cast<FSTPSV_*>(*it_code)->get_pos()};
+            switch (SymbolType type {static_cast<FSTPSV_*>(*it_code)->get_type()}; type)
               {
               case SymbolType::parameter:
               case SymbolType::endogenous:
@@ -552,43 +556,42 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
                 assign_lhs(symbol_table.getName(type, var));
                 break;
               default:
-                throw FatalException{"FSTPSV: Unknown variable type"};
+                throw FatalException {"FSTPSV: Unknown variable type"};
               }
           }
           break;
         case Tags::FSTPT:
-          assign_lhs("T" + to_string(static_cast<FSTPT_ *>(*it_code)->get_pos() + 1));
+          assign_lhs("T" + to_string(static_cast<FSTPT_*>(*it_code)->get_pos() + 1));
           break;
         case Tags::FSTPST:
-          assign_lhs("T" + to_string(static_cast<FSTPST_ *>(*it_code)->get_pos() + 1));
+          assign_lhs("T" + to_string(static_cast<FSTPST_*>(*it_code)->get_pos() + 1));
           break;
         case Tags::FSTPU:
-          assign_lhs("u(" + to_string(static_cast<FSTPU_ *>(*it_code)->get_pos() + 1) + " + it_)");
+          assign_lhs("u(" + to_string(static_cast<FSTPU_*>(*it_code)->get_pos() + 1) + " + it_)");
           break;
         case Tags::FSTPSU:
-          assign_lhs("u(" + to_string(static_cast<FSTPSU_ *>(*it_code)->get_pos() + 1) + ")");
+          assign_lhs("u(" + to_string(static_cast<FSTPSU_*>(*it_code)->get_pos() + 1) + ")");
           break;
         case Tags::FSTPR:
-          assign_lhs("residual(" + to_string(static_cast<FSTPR_ *>(*it_code)->get_pos() + 1) + ")");
+          assign_lhs("residual(" + to_string(static_cast<FSTPR_*>(*it_code)->get_pos() + 1) + ")");
           break;
         case Tags::FSTPG:
-          assign_lhs("g1(" + to_string(static_cast<FSTPG_ *>(*it_code)->get_pos() + 1) + ")");
+          assign_lhs("g1(" + to_string(static_cast<FSTPG_*>(*it_code)->get_pos() + 1) + ")");
           break;
         case Tags::FSTPG2:
           {
-            int eq {static_cast<FSTPG2_ *>(*it_code)->get_row()};
-            int var {static_cast<FSTPG2_ *>(*it_code)->get_col()};
-            assign_lhs("jacob(" + to_string(eq+1) + ", " + to_string(var+1) + ")");
+            int eq {static_cast<FSTPG2_*>(*it_code)->get_row()};
+            int var {static_cast<FSTPG2_*>(*it_code)->get_col()};
+            assign_lhs("jacob(" + to_string(eq + 1) + ", " + to_string(var + 1) + ")");
           }
           break;
         case Tags::FSTPG3:
           {
-            int eq {static_cast<FSTPG3_ *>(*it_code)->get_row()};
-            int var {static_cast<FSTPG3_ *>(*it_code)->get_col()};
-            int lag {static_cast<FSTPG3_ *>(*it_code)->get_lag()};
-            int col_pos {static_cast<FSTPG3_ *>(*it_code)->get_col_pos()};
-            string matrix_name { [&]
-            {
+            int eq {static_cast<FSTPG3_*>(*it_code)->get_row()};
+            int var {static_cast<FSTPG3_*>(*it_code)->get_col()};
+            int lag {static_cast<FSTPG3_*>(*it_code)->get_lag()};
+            int col_pos {static_cast<FSTPG3_*>(*it_code)->get_col_pos()};
+            string matrix_name {[&] {
               switch (equation_type)
                 {
                 case ExpressionType::FirstEndoDerivative:
@@ -598,17 +601,18 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
                 case ExpressionType::FirstExodetDerivative:
                   return "jacob_exo_det";
                 default:
-                  throw FatalException{"Unknown equation type " + to_string(static_cast<int>(equation_type))};
+                  throw FatalException {"Unknown equation type "
+                                        + to_string(static_cast<int>(equation_type))};
                 }
-            }() };
+            }()};
 
-            assign_lhs(matrix_name + "(" + to_string(eq+1) + ", " + to_string(col_pos+1)
-                       + " [var=" + to_string(var+1) + ", lag=" + to_string(lag) + "])");
+            assign_lhs(matrix_name + "(" + to_string(eq + 1) + ", " + to_string(col_pos + 1)
+                       + " [var=" + to_string(var + 1) + ", lag=" + to_string(lag) + "])");
           }
           break;
         case Tags::FUNARY:
           {
-            UnaryOpcode op {static_cast<FUNARY_ *>(*it_code)->get_op_type()};
+            UnaryOpcode op {static_cast<FUNARY_*>(*it_code)->get_op_type()};
             auto [arg, prec_arg, op_arg] {Stack.top()};
             Stack.pop();
 
@@ -618,8 +622,7 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
             if (op == UnaryOpcode::uminus)
               s << "(";
 
-            s << [&]
-            {
+            s << [&] {
               switch (op)
                 {
                 case UnaryOpcode::uminus:
@@ -670,23 +673,22 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
                   return "steady_state";
                 case UnaryOpcode::steadyStateParamDeriv:
                 case UnaryOpcode::steadyStateParam2ndDeriv:
-                  throw FatalException{"Unexpected derivative of steady_state operator"};
+                  throw FatalException {"Unexpected derivative of steady_state operator"};
                 case UnaryOpcode::expectation:
-                  throw FatalException{"Unexpected expectation operator"};
+                  throw FatalException {"Unexpected expectation operator"};
                 case UnaryOpcode::diff:
                   return "diff";
                 case UnaryOpcode::adl:
                   return "adl";
                 }
-              throw FatalException{"Unknown opcode"};
+              throw FatalException {"Unknown opcode"};
             }();
 
             /* Print argument. Enclose it with parentheses if:
                - current opcode is not uminus, or
                - current opcode is uminus and argument has lowest precedence */
             bool close_parenthesis {false};
-            if (op != UnaryOpcode::uminus
-                || (op == UnaryOpcode::uminus && prec_arg < 100))
+            if (op != UnaryOpcode::uminus || (op == UnaryOpcode::uminus && prec_arg < 100))
               {
                 s << "(";
                 close_parenthesis = true;
@@ -704,7 +706,7 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
           break;
         case Tags::FBINARY:
           {
-            BinaryOpcode op {static_cast<FBINARY_ *>(*it_code)->get_op_type()};
+            BinaryOpcode op {static_cast<FBINARY_*>(*it_code)->get_op_type()};
             auto [arg2, prec_arg2, op_arg2] {Stack.top()};
             Stack.pop();
             auto [arg1, prec_arg1, op_arg1] {Stack.top()};
@@ -718,14 +720,14 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
               {
                 auto [arg3, prec_arg3, op_arg3] {Stack.top()};
                 Stack.pop();
-                Stack.emplace((it_code == faulty_op ? "{PowerDeriv}(" : "PowerDeriv(") + arg1
-                              + ", " + arg2 + ", " + arg3 + ")", 100, nullopt);
+                Stack.emplace((it_code == faulty_op ? "{PowerDeriv}(" : "PowerDeriv(") + arg1 + ", "
+                                  + arg2 + ", " + arg3 + ")",
+                              100, nullopt);
               }
             else
               {
                 ostringstream s;
-                int prec { [&]
-                {
+                int prec {[&] {
                   switch (op)
                     {
                     case BinaryOpcode::equal:
@@ -751,8 +753,8 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
                     case BinaryOpcode::max:
                       return 100;
                     }
-                  throw FatalException{"Unknown opcode"};
-                }() };
+                  throw FatalException {"Unknown opcode"};
+                }()};
 
                 /* Print left argument. If left argument has a lower
                    precedence, or if current and left argument are both power
@@ -768,40 +770,39 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
                 if (close_parenthesis)
                   s << ")";
 
-                s << [&]
-                {
+                s << [&] {
                   switch (op)
-                  {
-                  case BinaryOpcode::plus:
-                    return "+";
-                  case BinaryOpcode::minus:
-                    return "-";
-                  case BinaryOpcode::times:
-                    return "*";
-                  case BinaryOpcode::divide:
-                    return it_code == faulty_op ? "{ / }" : "/";
-                  case BinaryOpcode::less:
-                    return " < ";
-                  case BinaryOpcode::greater:
-                    return " > ";
-                  case BinaryOpcode::lessEqual:
-                    return " <= ";
-                  case BinaryOpcode::greaterEqual:
-                    return " >= ";
-                  case BinaryOpcode::equalEqual:
-                    return " == ";
-                  case BinaryOpcode::different:
-                    return " != ";
-                  case BinaryOpcode::power:
-                    return it_code == faulty_op ? "{ ^ }" : "^";
-                  case BinaryOpcode::powerDeriv:
-                  case BinaryOpcode::max:
-                  case BinaryOpcode::min:
-                    throw FatalException{"Should not arrive here"};
-                  case BinaryOpcode::equal:
-                    return " = ";
-                  }
-                  throw FatalException{"Unknown opcode"};
+                    {
+                    case BinaryOpcode::plus:
+                      return "+";
+                    case BinaryOpcode::minus:
+                      return "-";
+                    case BinaryOpcode::times:
+                      return "*";
+                    case BinaryOpcode::divide:
+                      return it_code == faulty_op ? "{ / }" : "/";
+                    case BinaryOpcode::less:
+                      return " < ";
+                    case BinaryOpcode::greater:
+                      return " > ";
+                    case BinaryOpcode::lessEqual:
+                      return " <= ";
+                    case BinaryOpcode::greaterEqual:
+                      return " >= ";
+                    case BinaryOpcode::equalEqual:
+                      return " == ";
+                    case BinaryOpcode::different:
+                      return " != ";
+                    case BinaryOpcode::power:
+                      return it_code == faulty_op ? "{ ^ }" : "^";
+                    case BinaryOpcode::powerDeriv:
+                    case BinaryOpcode::max:
+                    case BinaryOpcode::min:
+                      throw FatalException {"Should not arrive here"};
+                    case BinaryOpcode::equal:
+                      return " = ";
+                    }
+                  throw FatalException {"Unknown opcode"};
                 }();
 
                 /* Print right argument. Add parenthesis around right argument if:
@@ -812,7 +813,8 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
                 close_parenthesis = false;
                 if (prec_arg2 < prec
                     || (op == BinaryOpcode::power && op_arg2 == BinaryOpcode::power)
-                    || (prec_arg2 == prec && (op == BinaryOpcode::minus || op == BinaryOpcode::divide)))
+                    || (prec_arg2 == prec
+                        && (op == BinaryOpcode::minus || op == BinaryOpcode::divide)))
                   {
                     s << "(";
                     close_parenthesis = true;
@@ -827,7 +829,7 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
           break;
         case Tags::FTRINARY:
           {
-            TrinaryOpcode op {static_cast<FTRINARY_ *>(*it_code)->get_op_type()};
+            TrinaryOpcode op {static_cast<FTRINARY_*>(*it_code)->get_op_type()};
             auto [arg3, prec_arg3, op_arg3] {Stack.top()};
             Stack.pop();
             auto [arg2, prec_arg2, op_arg2] {Stack.top()};
@@ -835,8 +837,7 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
             auto [arg1, prec_arg1, op_arg1] {Stack.top()};
             Stack.pop();
 
-            string opname { [&]
-            {
+            string opname {[&] {
               switch (op)
                 {
                 case TrinaryOpcode::normcdf:
@@ -844,27 +845,26 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
                 case TrinaryOpcode::normpdf:
                   return "normpdf";
                 }
-              throw FatalException{"Unknown opcode"};
-            }() };
+              throw FatalException {"Unknown opcode"};
+            }()};
 
             Stack.emplace(opname + "(" + arg1 + ", " + arg2 + ", " + arg3 + ")", 100, nullopt);
           }
           break;
         case Tags::FCALL:
           {
-            auto *fc = static_cast<FCALL_ *>(*it_code);
+            auto* fc = static_cast<FCALL_*>(*it_code);
             string function_name {fc->get_function_name()};
-            int nb_input_arguments{fc->get_nb_input_arguments()};
-            int nb_add_input_arguments{fc->get_nb_add_input_arguments()};
+            int nb_input_arguments {fc->get_nb_input_arguments()};
+            int nb_add_input_arguments {fc->get_nb_add_input_arguments()};
             string arg_func_name {fc->get_arg_func_name()};
             ostringstream s;
 
-            auto print_args = [&](int nargs)
-            {
+            auto print_args = [&](int nargs) {
               vector<string> ss(nargs);
               for (int i {0}; i < nargs; i++)
                 {
-                  ss[nargs-i-1] = get<0>(Stack.top());
+                  ss[nargs - i - 1] = get<0>(Stack.top());
                   Stack.pop();
                 }
               for (int i {0}; i < nargs; i++)
@@ -888,12 +888,13 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
                 s << ")";
                 break;
               case ExternalFunctionCallType::numericalFirstDerivative:
-                s << function_name << "(" << arg_func_name << ", " << fc->get_row()+1 << ", {";
+                s << function_name << "(" << arg_func_name << ", " << fc->get_row() + 1 << ", {";
                 print_args(nb_add_input_arguments);
                 s << "})";
                 break;
               case ExternalFunctionCallType::numericalSecondDerivative:
-                s << function_name << "(" << arg_func_name << ", " << fc->get_row()+1 << ", " << fc->get_col()+1 << ", {";
+                s << function_name << "(" << arg_func_name << ", " << fc->get_row() + 1 << ", "
+                  << fc->get_col() + 1 << ", {";
                 print_args(nb_add_input_arguments);
                 s << "})";
                 break;
@@ -903,60 +904,67 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
           break;
         case Tags::FSTPTEF:
           {
-            int indx {static_cast<FSTPTEF_ *>(*it_code)->get_number()};
+            int indx {static_cast<FSTPTEF_*>(*it_code)->get_number()};
             switch (call_type)
-            {
-            case ExternalFunctionCallType::levelWithoutDerivative:
-              assign_lhs("TEF(" + to_string(indx+1) + ")");
-              break;
-            case ExternalFunctionCallType::levelWithFirstDerivative:
-              assign_lhs("[TEF(" + to_string(indx+1) + "), TEFD("  + to_string(indx+1) + ") ]");
-              break;
-            case ExternalFunctionCallType::levelWithFirstAndSecondDerivative:
-              assign_lhs("[TEF(" + to_string(indx+1) + "), TEFD("  + to_string(indx+1) + "), TEFDD("  + to_string(indx+1) + ") ]");
-              break;
-            default:
-              throw FatalException{"Unexpected external function call type"};
-            }
+              {
+              case ExternalFunctionCallType::levelWithoutDerivative:
+                assign_lhs("TEF(" + to_string(indx + 1) + ")");
+                break;
+              case ExternalFunctionCallType::levelWithFirstDerivative:
+                assign_lhs("[TEF(" + to_string(indx + 1) + "), TEFD(" + to_string(indx + 1)
+                           + ") ]");
+                break;
+              case ExternalFunctionCallType::levelWithFirstAndSecondDerivative:
+                assign_lhs("[TEF(" + to_string(indx + 1) + "), TEFD(" + to_string(indx + 1)
+                           + "), TEFDD(" + to_string(indx + 1) + ") ]");
+                break;
+              default:
+                throw FatalException {"Unexpected external function call type"};
+              }
           }
           break;
         case Tags::FLDTEF:
-          Stack.emplace("TEF(" + to_string(static_cast<FLDTEF_ *>(*it_code)->get_number()+1) + ")", 100, nullopt);
+          Stack.emplace("TEF(" + to_string(static_cast<FLDTEF_*>(*it_code)->get_number() + 1) + ")",
+                        100, nullopt);
           break;
         case Tags::FSTPTEFD:
           {
-            int indx {static_cast<FSTPTEFD_ *>(*it_code)->get_indx()};
-            int row {static_cast<FSTPTEFD_ *>(*it_code)->get_row()};
+            int indx {static_cast<FSTPTEFD_*>(*it_code)->get_indx()};
+            int row {static_cast<FSTPTEFD_*>(*it_code)->get_row()};
             if (call_type == ExternalFunctionCallType::numericalFirstDerivative)
-              assign_lhs("TEFD(" + to_string(indx+1) + ", " + to_string(row+1) + ")");
+              assign_lhs("TEFD(" + to_string(indx + 1) + ", " + to_string(row + 1) + ")");
             else if (call_type == ExternalFunctionCallType::separatelyProvidedFirstDerivative)
-              assign_lhs("TEFD(" + to_string(indx+1) + ")");
+              assign_lhs("TEFD(" + to_string(indx + 1) + ")");
           }
           break;
         case Tags::FLDTEFD:
           {
-            int indx {static_cast<FLDTEFD_ *>(*it_code)->get_indx()};
-            int row {static_cast<FLDTEFD_ *>(*it_code)->get_row()};
-            Stack.emplace("TEFD(" + to_string(indx+1) + ", " + to_string(row+1) + ")", 100, nullopt);
+            int indx {static_cast<FLDTEFD_*>(*it_code)->get_indx()};
+            int row {static_cast<FLDTEFD_*>(*it_code)->get_row()};
+            Stack.emplace("TEFD(" + to_string(indx + 1) + ", " + to_string(row + 1) + ")", 100,
+                          nullopt);
           }
           break;
         case Tags::FSTPTEFDD:
           {
-            int indx {static_cast<FSTPTEFDD_ *>(*it_code)->get_indx()};
-            int row {static_cast<FSTPTEFDD_ *>(*it_code)->get_row()};
-            int col {static_cast<FSTPTEFDD_ *>(*it_code)->get_col()};
+            int indx {static_cast<FSTPTEFDD_*>(*it_code)->get_indx()};
+            int row {static_cast<FSTPTEFDD_*>(*it_code)->get_row()};
+            int col {static_cast<FSTPTEFDD_*>(*it_code)->get_col()};
             if (call_type == ExternalFunctionCallType::numericalSecondDerivative)
-              assign_lhs("TEFDD(" + to_string(indx+1) + ", " + to_string(row+1) + ", " + to_string(col+1) + ")");
+              assign_lhs("TEFDD(" + to_string(indx + 1) + ", " + to_string(row + 1) + ", "
+                         + to_string(col + 1) + ")");
             else if (call_type == ExternalFunctionCallType::separatelyProvidedSecondDerivative)
-              assign_lhs("TEFDD(" + to_string(indx+1) + ")");
+              assign_lhs("TEFDD(" + to_string(indx + 1) + ")");
           }
           break;
         case Tags::FLDTEFDD:
           {
-            int indx {static_cast<FLDTEFDD_ *>(*it_code)->get_indx()};
-            int row {static_cast<FLDTEFDD_ *>(*it_code)->get_row()};
-            int col {static_cast<FSTPTEFDD_ *>(*it_code)->get_col()};
-            Stack.emplace("TEFDD(" + to_string(indx+1) + ", " + to_string(row+1) + ", " + to_string(col+1) + ")", 100, nullopt);
+            int indx {static_cast<FLDTEFDD_*>(*it_code)->get_indx()};
+            int row {static_cast<FLDTEFDD_*>(*it_code)->get_row()};
+            int col {static_cast<FSTPTEFDD_*>(*it_code)->get_col()};
+            Stack.emplace("TEFDD(" + to_string(indx + 1) + ", " + to_string(row + 1) + ", "
+                              + to_string(col + 1) + ")",
+                          100, nullopt);
           }
           break;
         case Tags::FJMPIFEVAL:
@@ -968,23 +976,30 @@ Evaluate::print_expression(const Evaluate::it_code_type &expr_begin, const optio
           go_on = false;
           break;
         case Tags::FENDBLOCK:
-          throw FatalException{"Can't print FENDBLOCK"};
+          throw FatalException {"Can't print FENDBLOCK"};
         case Tags::FENDEQU:
-          throw FatalException{"Can't print FENDEQU"};
+          throw FatalException {"Can't print FENDEQU"};
         default:
-          throw FatalException{"In print_expression, unknown opcode "
-                               + to_string(static_cast<int>((*it_code)->op_code))};
+          throw FatalException {"In print_expression, unknown opcode "
+                                + to_string(static_cast<int>((*it_code)->op_code))};
         }
       it_code++;
     }
-  return { get<0>(Stack.top()), it_code };
+  return {get<0>(Stack.top()), it_code};
 }
 
 void
-Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size, double *__restrict__ x, int nb_row_x, double *__restrict__ params, const double *__restrict__ steady_y, double *__restrict__ u, int Per_u_, double *__restrict__ T, int T_nrows, map<int, double> &TEF, map<pair<int, int>, double> &TEFD, map<tuple<int, int, int>, double> &TEFDD, double *__restrict__ r, double *__restrict__ g1, double *__restrict__ jacob, double *__restrict__ jacob_exo, double *__restrict__ jacob_exo_det, bool evaluate, bool no_derivatives)
+Evaluate::evaluateBlock(int it_, int y_kmin, double* __restrict__ y, int y_size,
+                        double* __restrict__ x, int nb_row_x, double* __restrict__ params,
+                        const double* __restrict__ steady_y, double* __restrict__ u, int Per_u_,
+                        double* __restrict__ T, int T_nrows, map<int, double>& TEF,
+                        map<pair<int, int>, double>& TEFD, map<tuple<int, int, int>, double>& TEFDD,
+                        double* __restrict__ r, double* __restrict__ g1, double* __restrict__ jacob,
+                        double* __restrict__ jacob_exo, double* __restrict__ jacob_exo_det,
+                        bool evaluate, bool no_derivatives)
 {
-  auto it_code { currentBlockBeginning() };
-  int var{0}, lag{0};
+  auto it_code {currentBlockBeginning()};
+  int var {0}, lag {0};
   UnaryOpcode op1;
   BinaryOpcode op2;
   TrinaryOpcode op3;
@@ -997,12 +1012,12 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
   double ll;
   double rr;
   stack<double> Stack;
-  ExternalFunctionCallType call_type{ExternalFunctionCallType::levelWithoutDerivative};
+  ExternalFunctionCallType call_type {ExternalFunctionCallType::levelWithoutDerivative};
   it_code_type it_code_expr;
 
 #ifdef MATLAB_MEX_FILE
   if (utIsInterruptPending())
-    throw UserException{};
+    throw UserException {};
 #endif
 
   while (go_on)
@@ -1014,16 +1029,17 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           mexPrintf("FNUMEXPR\n");
 #endif
           it_code_expr = it_code;
-          switch (static_cast<FNUMEXPR_ *>(*it_code)->get_expression_type())
+          switch (static_cast<FNUMEXPR_*>(*it_code)->get_expression_type())
             {
             case ExpressionType::TemporaryTerm:
 #ifdef DEBUG
               mexPrintf("TemporaryTerm\n");
 #endif
               EQN_type = ExpressionType::TemporaryTerm;
-              EQN_equation = static_cast<FNUMEXPR_ *>(*it_code)->get_equation();
+              EQN_equation = static_cast<FNUMEXPR_*>(*it_code)->get_equation();
 #ifdef DEBUG
-              mexPrintf("EQN_equation=%d\n", EQN_equation); mexEvalString("drawnow;");
+              mexPrintf("EQN_equation=%d\n", EQN_equation);
+              mexEvalString("drawnow;");
 #endif
               break;
             case ExpressionType::ModelEquation:
@@ -1031,43 +1047,43 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
               mexPrintf("ModelEquation\n");
 #endif
               EQN_type = ExpressionType::ModelEquation;
-              EQN_equation = static_cast<FNUMEXPR_ *>(*it_code)->get_equation();
+              EQN_equation = static_cast<FNUMEXPR_*>(*it_code)->get_equation();
               break;
             case ExpressionType::FirstEndoDerivative:
 #ifdef DEBUG
               mexPrintf("FirstEndoDerivative\n");
 #endif
               EQN_type = ExpressionType::FirstEndoDerivative;
-              EQN_equation = static_cast<FNUMEXPR_ *>(*it_code)->get_equation();
-              EQN_dvar1 = static_cast<FNUMEXPR_ *>(*it_code)->get_dvariable1();
-              EQN_lag1 = static_cast<FNUMEXPR_ *>(*it_code)->get_lag1();
+              EQN_equation = static_cast<FNUMEXPR_*>(*it_code)->get_equation();
+              EQN_dvar1 = static_cast<FNUMEXPR_*>(*it_code)->get_dvariable1();
+              EQN_lag1 = static_cast<FNUMEXPR_*>(*it_code)->get_lag1();
               break;
             case ExpressionType::FirstExoDerivative:
 #ifdef DEBUG
               mexPrintf("FirstExoDerivative\n");
 #endif
               EQN_type = ExpressionType::FirstExoDerivative;
-              EQN_equation = static_cast<FNUMEXPR_ *>(*it_code)->get_equation();
-              EQN_dvar1 = static_cast<FNUMEXPR_ *>(*it_code)->get_dvariable1();
-              EQN_lag1 = static_cast<FNUMEXPR_ *>(*it_code)->get_lag1();
+              EQN_equation = static_cast<FNUMEXPR_*>(*it_code)->get_equation();
+              EQN_dvar1 = static_cast<FNUMEXPR_*>(*it_code)->get_dvariable1();
+              EQN_lag1 = static_cast<FNUMEXPR_*>(*it_code)->get_lag1();
               break;
             case ExpressionType::FirstExodetDerivative:
 #ifdef DEBUG
               mexPrintf("FirstExodetDerivative\n");
 #endif
               EQN_type = ExpressionType::FirstExodetDerivative;
-              EQN_equation = static_cast<FNUMEXPR_ *>(*it_code)->get_equation();
-              EQN_dvar1 = static_cast<FNUMEXPR_ *>(*it_code)->get_dvariable1();
-              EQN_lag1 = static_cast<FNUMEXPR_ *>(*it_code)->get_lag1();
+              EQN_equation = static_cast<FNUMEXPR_*>(*it_code)->get_equation();
+              EQN_dvar1 = static_cast<FNUMEXPR_*>(*it_code)->get_dvariable1();
+              EQN_lag1 = static_cast<FNUMEXPR_*>(*it_code)->get_lag1();
               break;
             }
           break;
         case Tags::FLDV:
-          //load a variable in the processor
-          switch (static_cast<FLDV_ *>(*it_code)->get_type())
+          // load a variable in the processor
+          switch (static_cast<FLDV_*>(*it_code)->get_type())
             {
             case SymbolType::parameter:
-              var = static_cast<FLDV_ *>(*it_code)->get_pos();
+              var = static_cast<FLDV_*>(*it_code)->get_pos();
 #ifdef DEBUG
               mexPrintf("FLDV Param[var=%d]\n", var);
               tmp_out << " params[" << var << "](" << params[var] << ")";
@@ -1075,31 +1091,38 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
               Stack.push(params[var]);
               break;
             case SymbolType::endogenous:
-              var = static_cast<FLDV_ *>(*it_code)->get_pos();
-              lag = static_cast<FLDV_ *>(*it_code)->get_lead_lag();
+              var = static_cast<FLDV_*>(*it_code)->get_pos();
+              lag = static_cast<FLDV_*>(*it_code)->get_lead_lag();
 #ifdef DEBUG
-              mexPrintf("FLDV y[var=%d, lag=%d, it_=%d], y_size=%d evaluate=%d, y[%d]=%f\n", var, lag, it_, y_size, evaluate, (it_+lag)*y_size+var, y[(it_+lag)*y_size+var]);
+              mexPrintf("FLDV y[var=%d, lag=%d, it_=%d], y_size=%d evaluate=%d, y[%d]=%f\n", var,
+                        lag, it_, y_size, evaluate, (it_ + lag) * y_size + var,
+                        y[(it_ + lag) * y_size + var]);
 #endif
-              Stack.push(y[(it_+lag)*y_size+var]);
+              Stack.push(y[(it_ + lag) * y_size + var]);
 #ifdef DEBUG
-              tmp_out << " y[" << it_+lag << ", " << var << "](" << y[(it_+lag)*y_size+var] << ")";
+              tmp_out << " y[" << it_ + lag << ", " << var << "](" << y[(it_ + lag) * y_size + var]
+                      << ")";
 #endif
               break;
             case SymbolType::exogenous:
-              var = static_cast<FLDV_ *>(*it_code)->get_pos();
-              lag = static_cast<FLDV_ *>(*it_code)->get_lead_lag();
+              var = static_cast<FLDV_*>(*it_code)->get_pos();
+              lag = static_cast<FLDV_*>(*it_code)->get_lead_lag();
 #ifdef DEBUG
-              mexPrintf("FLDV x[var=%d, lag=%d, it_=%d], nb_row_x=%d evaluate=%d x[%d]=%f\n", var, lag, it_, nb_row_x, evaluate, it_+lag+var*nb_row_x, x[it_+lag+var*nb_row_x]);
-              //tmp_out << " x[" << it_+lag << ", " << var << "](" << x[it_+lag+var*nb_row_x] << ")";
+              mexPrintf("FLDV x[var=%d, lag=%d, it_=%d], nb_row_x=%d evaluate=%d x[%d]=%f\n", var,
+                        lag, it_, nb_row_x, evaluate, it_ + lag + var * nb_row_x,
+                        x[it_ + lag + var * nb_row_x]);
+              // tmp_out << " x[" << it_+lag << ", " << var << "](" << x[it_+lag+var*nb_row_x] <<
+              // ")";
 #endif
-              Stack.push(x[it_+lag+var*nb_row_x]);
+              Stack.push(x[it_ + lag + var * nb_row_x]);
               break;
             case SymbolType::exogenousDet:
-              throw FatalException{"FLDV: exogenous deterministic not supported"};
+              throw FatalException {"FLDV: exogenous deterministic not supported"};
               break;
             case SymbolType::modelLocalVariable:
 #ifdef DEBUG
-              mexPrintf("FLDV a local variable in Block %d Stack.size()=%d", block_num, Stack.size());
+              mexPrintf("FLDV a local variable in Block %d Stack.size()=%d", block_num,
+                        Stack.size());
               mexPrintf(" value=%f\n", Stack.top());
 #endif
               break;
@@ -1108,11 +1131,11 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
             }
           break;
         case Tags::FLDSV:
-          //load a variable in the processor
-          switch (static_cast<FLDSV_ *>(*it_code)->get_type())
+          // load a variable in the processor
+          switch (static_cast<FLDSV_*>(*it_code)->get_type())
             {
             case SymbolType::parameter:
-              var = static_cast<FLDSV_ *>(*it_code)->get_pos();
+              var = static_cast<FLDSV_*>(*it_code)->get_pos();
 #ifdef DEBUG
               mexPrintf("FLDSV Param[var=%d]=%f\n", var, params[var]);
               tmp_out << " params[" << var << "](" << params[var] << ")";
@@ -1120,7 +1143,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
               Stack.push(params[var]);
               break;
             case SymbolType::endogenous:
-              var = static_cast<FLDSV_ *>(*it_code)->get_pos();
+              var = static_cast<FLDSV_*>(*it_code)->get_pos();
 #ifdef DEBUG
               mexPrintf("FLDSV y[var=%d]=%f\n", var, y[var]);
               tmp_out << " y[" << var << "](" << y[var] << ")";
@@ -1128,7 +1151,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
               Stack.push(y[var]);
               break;
             case SymbolType::exogenous:
-              var = static_cast<FLDSV_ *>(*it_code)->get_pos();
+              var = static_cast<FLDSV_*>(*it_code)->get_pos();
 #ifdef DEBUG
               mexPrintf("FLDSV x[var=%d]\n", var);
               tmp_out << " x[" << var << "](" << x[var] << ")";
@@ -1136,11 +1159,12 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
               Stack.push(x[var]);
               break;
             case SymbolType::exogenousDet:
-              throw FatalException{"FLDSV: exogenous deterministic not supported"};
+              throw FatalException {"FLDSV: exogenous deterministic not supported"};
               break;
             case SymbolType::modelLocalVariable:
 #ifdef DEBUG
-              mexPrintf("FLDSV a local variable in Block %d Stack.size()=%d", block_num, Stack.size());
+              mexPrintf("FLDSV a local variable in Block %d Stack.size()=%d", block_num,
+                        Stack.size());
               mexPrintf(" value=%f\n", Stack.top());
 #endif
               break;
@@ -1149,36 +1173,37 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
             }
           break;
         case Tags::FLDVS:
-          //load a variable in the processor
-          switch (static_cast<FLDVS_ *>(*it_code)->get_type())
+          // load a variable in the processor
+          switch (static_cast<FLDVS_*>(*it_code)->get_type())
             {
             case SymbolType::parameter:
-              var = static_cast<FLDVS_ *>(*it_code)->get_pos();
+              var = static_cast<FLDVS_*>(*it_code)->get_pos();
 #ifdef DEBUG
               mexPrintf("params[%d]\n", var);
 #endif
               Stack.push(params[var]);
               break;
             case SymbolType::endogenous:
-              var = static_cast<FLDVS_ *>(*it_code)->get_pos();
+              var = static_cast<FLDVS_*>(*it_code)->get_pos();
 #ifdef DEBUG
               mexPrintf("FLDVS steady_y[%d]\n", var);
 #endif
               Stack.push(steady_y[var]);
               break;
             case SymbolType::exogenous:
-              var = static_cast<FLDVS_ *>(*it_code)->get_pos();
+              var = static_cast<FLDVS_*>(*it_code)->get_pos();
 #ifdef DEBUG
               mexPrintf("FLDVS x[%d] \n", var);
 #endif
               Stack.push(x[var]);
               break;
             case SymbolType::exogenousDet:
-              throw FatalException{"FLDVS: exogenous deterministic not supported"};
+              throw FatalException {"FLDVS: exogenous deterministic not supported"};
               break;
             case SymbolType::modelLocalVariable:
 #ifdef DEBUG
-              mexPrintf("FLDVS a local variable in Block %d Stack.size()=%d", block_num, Stack.size());
+              mexPrintf("FLDVS a local variable in Block %d Stack.size()=%d", block_num,
+                        Stack.size());
               mexPrintf(" value=%f\n", Stack.top());
 #endif
               break;
@@ -1187,17 +1212,18 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
             }
           break;
         case Tags::FLDT:
-          //load a temporary variable in the processor
-          var = static_cast<FLDT_ *>(*it_code)->get_pos();
+          // load a temporary variable in the processor
+          var = static_cast<FLDT_*>(*it_code)->get_pos();
 #ifdef DEBUG
-          mexPrintf("FLDT T[it_=%d var=%d, y_kmin=%d, y_kmax=%d == %d]=>%f\n", it_, var, y_kmin, y_kmax, var*T_nrows+it_, T[var*T_nrows+it_-y_kmin]);
-          tmp_out << " T[" << it_ << ", " << var << "](" << T[var*T_nrows+it_-y_kmin] << ")";
+          mexPrintf("FLDT T[it_=%d var=%d, y_kmin=%d, y_kmax=%d == %d]=>%f\n", it_, var, y_kmin,
+                    y_kmax, var * T_nrows + it_, T[var * T_nrows + it_ - y_kmin]);
+          tmp_out << " T[" << it_ << ", " << var << "](" << T[var * T_nrows + it_ - y_kmin] << ")";
 #endif
-          Stack.push(T[var*T_nrows+it_-y_kmin]);
+          Stack.push(T[var * T_nrows + it_ - y_kmin]);
           break;
         case Tags::FLDST:
-          //load a temporary variable in the processor
-          var = static_cast<FLDST_ *>(*it_code)->get_pos();
+          // load a temporary variable in the processor
+          var = static_cast<FLDST_*>(*it_code)->get_pos();
 #ifdef DEBUG
           mexPrintf("FLDST T[%d]", var);
 #endif
@@ -1208,8 +1234,8 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
 #endif
           break;
         case Tags::FLDU:
-          //load u variable in the processor
-          var = static_cast<FLDU_ *>(*it_code)->get_pos();
+          // load u variable in the processor
+          var = static_cast<FLDU_*>(*it_code)->get_pos();
           var += Per_u_;
 #ifdef DEBUG
           mexPrintf("FLDU u[%d]\n", var);
@@ -1218,8 +1244,8 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           Stack.push(u[var]);
           break;
         case Tags::FLDSU:
-          //load u variable in the processor
-          var = static_cast<FLDSU_ *>(*it_code)->get_pos();
+          // load u variable in the processor
+          var = static_cast<FLDSU_*>(*it_code)->get_pos();
 #ifdef DEBUG
           mexPrintf("FLDSU u[%d]\n", var);
           tmp_out << " u[" << var << "](" << u[var] << ")";
@@ -1227,15 +1253,15 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           Stack.push(u[var]);
           break;
         case Tags::FLDR:
-          //load u variable in the processor
-          var = static_cast<FLDR_ *>(*it_code)->get_pos();
+          // load u variable in the processor
+          var = static_cast<FLDR_*>(*it_code)->get_pos();
 #ifdef DEBUG
           mexPrintf("FLDR r[%d]\n", var);
 #endif
           Stack.push(r[var]);
           break;
         case Tags::FLDZ:
-          //load 0 in the processor
+          // load 0 in the processor
 #ifdef DEBUG
           mexPrintf("FLDZ\n");
 #endif
@@ -1245,8 +1271,8 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
 #endif
           break;
         case Tags::FLDC:
-          //load a numerical constant in the processor
-          ll = static_cast<FLDC_ *>(*it_code)->get_value();
+          // load a numerical constant in the processor
+          ll = static_cast<FLDC_*>(*it_code)->get_value();
 #ifdef DEBUG
           mexPrintf("FLDC = %f\n", ll);
           tmp_out << " " << ll;
@@ -1255,11 +1281,11 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           Stack.push(ll);
           break;
         case Tags::FSTPV:
-          //load a variable in the processor
-          switch (static_cast<FSTPV_ *>(*it_code)->get_type())
+          // load a variable in the processor
+          switch (static_cast<FSTPV_*>(*it_code)->get_type())
             {
             case SymbolType::parameter:
-              var = static_cast<FSTPV_ *>(*it_code)->get_pos();
+              var = static_cast<FSTPV_*>(*it_code)->get_pos();
 #ifdef DEBUG
               mexPrintf("FSTPV params[%d]\n", var);
 #endif
@@ -1267,46 +1293,48 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
               Stack.pop();
               break;
             case SymbolType::endogenous:
-              var = static_cast<FSTPV_ *>(*it_code)->get_pos();
-              lag = static_cast<FSTPV_ *>(*it_code)->get_lead_lag();
-              y[(it_+lag)*y_size+var] = Stack.top();
+              var = static_cast<FSTPV_*>(*it_code)->get_pos();
+              lag = static_cast<FSTPV_*>(*it_code)->get_lead_lag();
+              y[(it_ + lag) * y_size + var] = Stack.top();
 #ifdef DEBUG
               tmp_out << "=>";
-              mexPrintf(" y[%d, %d](%f)=%s\n", it_+lag, var, y[(it_+lag)*y_size+var], tmp_out.str().c_str());
+              mexPrintf(" y[%d, %d](%f)=%s\n", it_ + lag, var, y[(it_ + lag) * y_size + var],
+                        tmp_out.str().c_str());
               tmp_out.str("");
 #endif
               Stack.pop();
               break;
             case SymbolType::exogenous:
-              var = static_cast<FSTPV_ *>(*it_code)->get_pos();
-              lag = static_cast<FSTPV_ *>(*it_code)->get_lead_lag();
-              x[it_+lag+var*nb_row_x] = Stack.top();
+              var = static_cast<FSTPV_*>(*it_code)->get_pos();
+              lag = static_cast<FSTPV_*>(*it_code)->get_lead_lag();
+              x[it_ + lag + var * nb_row_x] = Stack.top();
 #ifdef DEBUG
               tmp_out << "=>";
-              mexPrintf(" x[%d, %d](%f)=%s\n", it_+lag, var, x[it_+lag+var*nb_row_x], tmp_out.str().c_str());
+              mexPrintf(" x[%d, %d](%f)=%s\n", it_ + lag, var, x[it_ + lag + var * nb_row_x],
+                        tmp_out.str().c_str());
               tmp_out.str("");
 #endif
 
               Stack.pop();
               break;
             case SymbolType::exogenousDet:
-              throw FatalException{"FSTPV: exogenous deterministic not supported"};
+              throw FatalException {"FSTPV: exogenous deterministic not supported"};
               break;
             default:
               mexPrintf("FSTPV: Unknown variable type\n");
             }
           break;
         case Tags::FSTPSV:
-          //load a variable in the processor
-          switch (static_cast<FSTPSV_ *>(*it_code)->get_type())
+          // load a variable in the processor
+          switch (static_cast<FSTPSV_*>(*it_code)->get_type())
             {
             case SymbolType::parameter:
-              var = static_cast<FSTPSV_ *>(*it_code)->get_pos();
+              var = static_cast<FSTPSV_*>(*it_code)->get_pos();
               params[var] = Stack.top();
               Stack.pop();
               break;
             case SymbolType::endogenous:
-              var = static_cast<FSTPSV_ *>(*it_code)->get_pos();
+              var = static_cast<FSTPSV_*>(*it_code)->get_pos();
               y[var] = Stack.top();
 #ifdef DEBUG
               tmp_out << "=>";
@@ -1316,43 +1344,44 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
               Stack.pop();
               break;
             case SymbolType::exogenous:
-              var = static_cast<FSTPSV_ *>(*it_code)->get_pos();
+              var = static_cast<FSTPSV_*>(*it_code)->get_pos();
               x[var] = Stack.top();
 #ifdef DEBUG
               tmp_out << "=>";
-              mexPrintf(" x[%d, %d](%f)=%s\n", it_+lag, var, x[var], tmp_out.str().c_str());
+              mexPrintf(" x[%d, %d](%f)=%s\n", it_ + lag, var, x[var], tmp_out.str().c_str());
               tmp_out.str("");
 #endif
               Stack.pop();
               break;
             case SymbolType::exogenousDet:
-              throw FatalException{"FSTPSV: exogenous deterministic not supported"};
+              throw FatalException {"FSTPSV: exogenous deterministic not supported"};
               break;
             default:
               mexPrintf("FSTPSV: Unknown variable type\n");
             }
           break;
         case Tags::FSTPT:
-          //store in a temporary variable from the processor
+          // store in a temporary variable from the processor
 #ifdef DEBUG
           mexPrintf("FSTPT\n");
 #endif
-          var = static_cast<FSTPT_ *>(*it_code)->get_pos();
-          T[var*T_nrows+it_-y_kmin] = Stack.top();
+          var = static_cast<FSTPT_*>(*it_code)->get_pos();
+          T[var * T_nrows + it_ - y_kmin] = Stack.top();
 #ifdef DEBUG
           tmp_out << "=>";
-          mexPrintf(" T[%d, %d](%f)=%s\n", it_, var, T[var*T_nrows+it_-y_kmin], tmp_out.str().c_str());
+          mexPrintf(" T[%d, %d](%f)=%s\n", it_, var, T[var * T_nrows + it_ - y_kmin],
+                    tmp_out.str().c_str());
           tmp_out.str("");
 #endif
 
           Stack.pop();
           break;
         case Tags::FSTPST:
-          //store in a temporary variable from the processor
+          // store in a temporary variable from the processor
 #ifdef DEBUG
           mexPrintf("FSTPST\n");
 #endif
-          var = static_cast<FSTPST_ *>(*it_code)->get_pos();
+          var = static_cast<FSTPST_*>(*it_code)->get_pos();
 #ifdef DEBUG
           mexPrintf("var=%d\n", var);
 #endif
@@ -1365,8 +1394,8 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           Stack.pop();
           break;
         case Tags::FSTPU:
-          //store in u variable from the processor
-          var = static_cast<FSTPU_ *>(*it_code)->get_pos();
+          // store in u variable from the processor
+          var = static_cast<FSTPU_*>(*it_code)->get_pos();
           var += Per_u_;
 #ifdef DEBUG
           mexPrintf("FSTPU\n");
@@ -1381,8 +1410,8 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           Stack.pop();
           break;
         case Tags::FSTPSU:
-          //store in u variable from the processor
-          var = static_cast<FSTPSU_ *>(*it_code)->get_pos();
+          // store in u variable from the processor
+          var = static_cast<FSTPSU_*>(*it_code)->get_pos();
 #ifdef DEBUG
           /*if (var >= u_count_alloc || var < 0)
             mexPrintf("Erreur var=%d\n", var);*/
@@ -1396,8 +1425,8 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           Stack.pop();
           break;
         case Tags::FSTPR:
-          //store in residual variable from the processor
-          var = static_cast<FSTPR_ *>(*it_code)->get_pos();
+          // store in residual variable from the processor
+          var = static_cast<FSTPR_*>(*it_code)->get_pos();
 #ifdef DEBUG
           tmp_out << "=>";
           mexPrintf("FSTPR r[%d]", var);
@@ -1412,12 +1441,12 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           Stack.pop();
           break;
         case Tags::FSTPG:
-          //store in derivative (g) variable from the processor
+          // store in derivative (g) variable from the processor
 #ifdef DEBUG
           mexPrintf("FSTPG\n");
           mexEvalString("drawnow;");
 #endif
-          var = static_cast<FSTPG_ *>(*it_code)->get_pos();
+          var = static_cast<FSTPG_*>(*it_code)->get_pos();
           g1[var] = Stack.top();
 #ifdef DEBUG
           tmp_out << "=>";
@@ -1428,21 +1457,22 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           break;
 
         case Tags::FSTPG2:
-          //store in the jacobian matrix
+          // store in the jacobian matrix
           rr = Stack.top();
           if (EQN_type != ExpressionType::FirstEndoDerivative)
-            throw FatalException{"In compute_block_time, impossible case " + to_string(static_cast<int>(EQN_type))
-                                 + " not implement in static jacobian"};
-          eq = static_cast<FSTPG2_ *>(*it_code)->get_row();
-          var = static_cast<FSTPG2_ *>(*it_code)->get_col();
+            throw FatalException {"In compute_block_time, impossible case "
+                                  + to_string(static_cast<int>(EQN_type))
+                                  + " not implement in static jacobian"};
+          eq = static_cast<FSTPG2_*>(*it_code)->get_row();
+          var = static_cast<FSTPG2_*>(*it_code)->get_col();
 #ifdef DEBUG
           mexPrintf("FSTPG2 eq=%d, var=%d\n", eq, var);
           mexEvalString("drawnow;");
 #endif
-          jacob[eq + size*var] = rr;
+          jacob[eq + size * var] = rr;
           break;
         case Tags::FSTPG3:
-          //store in derivative (g) variable from the processor
+          // store in derivative (g) variable from the processor
 #ifdef DEBUG
           mexPrintf("FSTPG3 Evaluate=%d\n", evaluate);
           mexEvalString("drawnow;");
@@ -1457,54 +1487,55 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           switch (EQN_type)
             {
             case ExpressionType::FirstEndoDerivative:
-              eq = static_cast<FSTPG3_ *>(*it_code)->get_row();
-              var = static_cast<FSTPG3_ *>(*it_code)->get_col();
-              lag = static_cast<FSTPG3_ *>(*it_code)->get_lag();
-              pos_col = static_cast<FSTPG3_ *>(*it_code)->get_col_pos();
+              eq = static_cast<FSTPG3_*>(*it_code)->get_row();
+              var = static_cast<FSTPG3_*>(*it_code)->get_col();
+              lag = static_cast<FSTPG3_*>(*it_code)->get_lag();
+              pos_col = static_cast<FSTPG3_*>(*it_code)->get_col_pos();
 #ifdef DEBUG
               mexPrintf("Endo eq=%d, pos_col=%d, size=%d, jacob=%x\n", eq, pos_col, size, jacob);
               mexPrintf("jacob=%x\n", jacob);
 #endif
-              jacob[eq + size*pos_col] = rr;
+              jacob[eq + size * pos_col] = rr;
               break;
             case ExpressionType::FirstExoDerivative:
-              //eq = static_cast<FSTPG3_ *>(*it_code)->get_row();
+              // eq = static_cast<FSTPG3_ *>(*it_code)->get_row();
               eq = EQN_equation;
-              var = static_cast<FSTPG3_ *>(*it_code)->get_col();
-              lag = static_cast<FSTPG3_ *>(*it_code)->get_lag();
-              pos_col = static_cast<FSTPG3_ *>(*it_code)->get_col_pos();
+              var = static_cast<FSTPG3_*>(*it_code)->get_col();
+              lag = static_cast<FSTPG3_*>(*it_code)->get_lag();
+              pos_col = static_cast<FSTPG3_*>(*it_code)->get_col_pos();
 #ifdef DEBUG
               mexPrintf("Exo eq=%d, pos_col=%d, size=%d\n", eq, pos_col, size);
               mexEvalString("drawnow;");
 #endif
-              jacob_exo[eq + size*pos_col] = rr;
+              jacob_exo[eq + size * pos_col] = rr;
               break;
             case ExpressionType::FirstExodetDerivative:
-              //eq = static_cast<FSTPG3_ *>(*it_code)->get_row();
+              // eq = static_cast<FSTPG3_ *>(*it_code)->get_row();
               eq = EQN_equation;
-              var = static_cast<FSTPG3_ *>(*it_code)->get_col();
-              lag = static_cast<FSTPG3_ *>(*it_code)->get_lag();
-              pos_col = static_cast<FSTPG3_ *>(*it_code)->get_col_pos();
+              var = static_cast<FSTPG3_*>(*it_code)->get_col();
+              lag = static_cast<FSTPG3_*>(*it_code)->get_lag();
+              pos_col = static_cast<FSTPG3_*>(*it_code)->get_col_pos();
 #ifdef DEBUG
               mexPrintf("Exo det eq=%d, pos_col=%d, size=%d\n", eq, pos_col, size);
               mexEvalString("drawnow;");
 #endif
 
-              jacob_exo_det[eq + size*pos_col] = rr;
+              jacob_exo_det[eq + size * pos_col] = rr;
               break;
             default:
-              throw FatalException{"In compute_block_time, variable " + to_string(static_cast<int>(EQN_type)) + " not used yet"};
+              throw FatalException {"In compute_block_time, variable "
+                                    + to_string(static_cast<int>(EQN_type)) + " not used yet"};
             }
-// #ifdef DEBUG
-//           tmp_out << "=>";
-//           mexPrintf(" g1[%d](%f)=%s\n", var, g1[var], tmp_out.str().c_str());
-//           tmp_out.str("");
-// #endif
+          // #ifdef DEBUG
+          //           tmp_out << "=>";
+          //           mexPrintf(" g1[%d](%f)=%s\n", var, g1[var], tmp_out.str().c_str());
+          //           tmp_out.str("");
+          // #endif
           Stack.pop();
           break;
 
         case Tags::FBINARY:
-          op2 = static_cast<FBINARY_ *>(*it_code)->get_op_type();
+          op2 = static_cast<FBINARY_*>(*it_code)->get_op_type();
 #ifdef DEBUG
           mexPrintf("FBINARY, op=%d\n", static_cast<int>(op2));
 #endif
@@ -1537,7 +1568,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 feclearexcept(FE_ALL_EXCEPT);
                 double tmp {v1 / v2};
                 if (fetestexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW))
-                  throw DivideException{v1, v2, error_location(it_code_expr, it_code, it_)};
+                  throw DivideException {v1, v2, error_location(it_code_expr, it_code, it_)};
                 Stack.push(tmp);
               }
 #ifdef DEBUG
@@ -1585,7 +1616,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 feclearexcept(FE_ALL_EXCEPT);
                 double tmp {pow(v1, v2)};
                 if (fetestexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW))
-                  throw PowException{v1, v2, error_location(it_code_expr, it_code, it_)};
+                  throw PowException {v1, v2, error_location(it_code_expr, it_code, it_)};
                 Stack.push(tmp);
               }
 #ifdef DEBUG
@@ -1598,24 +1629,25 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 Stack.pop();
                 try
                   {
-                    if (fabs(v1) < power_deriv_near_zero && v2 > 0
-                        && derivOrder > v2
-                        && fabs(v2-nearbyint(v2)) < power_deriv_near_zero)
+                    if (fabs(v1) < power_deriv_near_zero && v2 > 0 && derivOrder > v2
+                        && fabs(v2 - nearbyint(v2)) < power_deriv_near_zero)
                       Stack.push(0.0);
                     else
                       {
                         feclearexcept(FE_ALL_EXCEPT);
-                        double dxp {pow(v1, v2-derivOrder)};
+                        double dxp {pow(v1, v2 - derivOrder)};
                         if (fetestexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW))
-                          throw PowException{v1, v2-derivOrder, error_location(it_code_expr, it_code, it_)};
+                          throw PowException {v1, v2 - derivOrder,
+                                              error_location(it_code_expr, it_code, it_)};
                         for (int i = 0; i < derivOrder; i++)
                           dxp *= v2--;
                         Stack.push(dxp);
                       }
                   }
-                catch (FloatingPointException &fpeh)
+                catch (FloatingPointException& fpeh)
                   {
-                    mexPrintf("%s\n      %s\n", fpeh.message.c_str(), error_location(it_code_expr, it_code, it_).c_str());
+                    mexPrintf("%s\n      %s\n", fpeh.message.c_str(),
+                              error_location(it_code_expr, it_code, it_).c_str());
                     go_on = false;
                   }
               }
@@ -1642,7 +1674,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
             }
           break;
         case Tags::FUNARY:
-          op1 = static_cast<FUNARY_ *>(*it_code)->get_op_type();
+          op1 = static_cast<FUNARY_*>(*it_code)->get_op_type();
           v1 = Stack.top();
           Stack.pop();
 #ifdef DEBUG
@@ -1668,7 +1700,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 feclearexcept(FE_ALL_EXCEPT);
                 double tmp {log(v1)};
                 if (fetestexcept(FE_DIVBYZERO | FE_INVALID))
-                  throw UnaryOpException{"log", v1, error_location(it_code_expr, it_code, it_)};
+                  throw UnaryOpException {"log", v1, error_location(it_code_expr, it_code, it_)};
                 Stack.push(tmp);
               }
 #ifdef DEBUG
@@ -1680,7 +1712,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 feclearexcept(FE_ALL_EXCEPT);
                 double tmp {log10(v1)};
                 if (fetestexcept(FE_DIVBYZERO | FE_INVALID))
-                  throw UnaryOpException{"log10", v1, error_location(it_code_expr, it_code, it_)};
+                  throw UnaryOpException {"log10", v1, error_location(it_code_expr, it_code, it_)};
                 Stack.push(tmp);
               }
 #ifdef DEBUG
@@ -1704,7 +1736,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 feclearexcept(FE_ALL_EXCEPT);
                 double tmp {tan(v1)};
                 if (fetestexcept(FE_OVERFLOW))
-                  throw UnaryOpException{"tan", v1, error_location(it_code_expr, it_code, it_)};
+                  throw UnaryOpException {"tan", v1, error_location(it_code_expr, it_code, it_)};
                 Stack.push(tmp);
               }
 #ifdef DEBUG
@@ -1716,7 +1748,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 feclearexcept(FE_ALL_EXCEPT);
                 double tmp {acos(v1)};
                 if (fetestexcept(FE_INVALID))
-                  throw UnaryOpException{"acos", v1, error_location(it_code_expr, it_code, it_)};
+                  throw UnaryOpException {"acos", v1, error_location(it_code_expr, it_code, it_)};
                 Stack.push(tmp);
               }
 #ifdef DEBUG
@@ -1728,7 +1760,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 feclearexcept(FE_ALL_EXCEPT);
                 double tmp {asin(v1)};
                 if (fetestexcept(FE_INVALID))
-                  throw UnaryOpException{"asin", v1, error_location(it_code_expr, it_code, it_)};
+                  throw UnaryOpException {"asin", v1, error_location(it_code_expr, it_code, it_)};
                 Stack.push(tmp);
               }
 #ifdef DEBUG
@@ -1746,7 +1778,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 feclearexcept(FE_ALL_EXCEPT);
                 double tmp {cosh(v1)};
                 if (fetestexcept(FE_OVERFLOW))
-                  throw UnaryOpException{"cosh", v1, error_location(it_code_expr, it_code, it_)};
+                  throw UnaryOpException {"cosh", v1, error_location(it_code_expr, it_code, it_)};
                 Stack.push(tmp);
               }
 #ifdef DEBUG
@@ -1758,7 +1790,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 feclearexcept(FE_ALL_EXCEPT);
                 double tmp {sinh(v1)};
                 if (fetestexcept(FE_OVERFLOW))
-                  throw UnaryOpException{"sinh", v1, error_location(it_code_expr, it_code, it_)};
+                  throw UnaryOpException {"sinh", v1, error_location(it_code_expr, it_code, it_)};
                 Stack.push(tmp);
               }
 #ifdef DEBUG
@@ -1776,7 +1808,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 feclearexcept(FE_ALL_EXCEPT);
                 double tmp {acosh(v1)};
                 if (fetestexcept(FE_INVALID))
-                  throw UnaryOpException{"acosh", v1, error_location(it_code_expr, it_code, it_)};
+                  throw UnaryOpException {"acosh", v1, error_location(it_code_expr, it_code, it_)};
                 Stack.push(tmp);
               }
 #ifdef DEBUG
@@ -1794,7 +1826,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 feclearexcept(FE_ALL_EXCEPT);
                 double tmp {atanh(v1)};
                 if (fetestexcept(FE_INVALID | FE_DIVBYZERO))
-                  throw UnaryOpException{"atanh", v1, error_location(it_code_expr, it_code, it_)};
+                  throw UnaryOpException {"atanh", v1, error_location(it_code_expr, it_code, it_)};
                 Stack.push(tmp);
               }
 #ifdef DEBUG
@@ -1806,7 +1838,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 feclearexcept(FE_ALL_EXCEPT);
                 double tmp {sqrt(v1)};
                 if (fetestexcept(FE_INVALID))
-                  throw UnaryOpException{"sqrt", v1, error_location(it_code_expr, it_code, it_)};
+                  throw UnaryOpException {"sqrt", v1, error_location(it_code_expr, it_code, it_)};
                 Stack.push(tmp);
               }
 #ifdef DEBUG
@@ -1847,9 +1879,11 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
             case UnaryOpcode::steadyState:
               throw FatalException {"Internal error: operator steady_state should not appear"};
             case UnaryOpcode::steadyStateParamDeriv:
-              throw FatalException {"Internal error: 1st derivative w.r.t. parameters of operator steady_state should not appear"};
+              throw FatalException {"Internal error: 1st derivative w.r.t. parameters of operator "
+                                    "steady_state should not appear"};
             case UnaryOpcode::steadyStateParam2ndDeriv:
-              throw FatalException {"Internal error: 2nd derivative w.r.t. parameters of operator steady_state should not appear"};
+              throw FatalException {"Internal error: 2nd derivative w.r.t. parameters of operator "
+                                    "steady_state should not appear"};
             case UnaryOpcode::expectation:
               throw FatalException {"Internal error: operator expectation should not appear"};
             case UnaryOpcode::diff:
@@ -1859,7 +1893,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
             }
           break;
         case Tags::FTRINARY:
-          op3 = static_cast<FTRINARY_ *>(*it_code)->get_op_type();
+          op3 = static_cast<FTRINARY_*>(*it_code)->get_op_type();
           v3 = Stack.top();
           Stack.pop();
           v2 = Stack.top();
@@ -1869,13 +1903,13 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           switch (op3)
             {
             case TrinaryOpcode::normcdf:
-              Stack.push(0.5*(1+erf((v1-v2)/v3/numbers::sqrt2)));
+              Stack.push(0.5 * (1 + erf((v1 - v2) / v3 / numbers::sqrt2)));
 #ifdef DEBUG
               tmp_out << " |normcdf(" << v1 << ", " << v2 << ", " << v3 << ")|";
 #endif
               break;
             case TrinaryOpcode::normpdf:
-              Stack.push(1/(v3*sqrt(2*numbers::pi)*exp(pow((v1-v2)/v3, 2)/2)));
+              Stack.push(1 / (v3 * sqrt(2 * numbers::pi) * exp(pow((v1 - v2) / v3, 2) / 2)));
 #ifdef DEBUG
               tmp_out << " |normpdf(" << v1 << ", " << v2 << ", " << v3 << ")|";
 #endif
@@ -1887,85 +1921,96 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           {
 #ifdef DEBUG
             mexPrintf("------------------------------\n");
-            mexPrintf("CALL "); mexEvalString("drawnow;");
+            mexPrintf("CALL ");
+            mexEvalString("drawnow;");
 #endif
-            auto *fc = static_cast<FCALL_ *>(*it_code);
+            auto* fc = static_cast<FCALL_*>(*it_code);
             string function_name = fc->get_function_name();
 #ifdef DEBUG
-            mexPrintf("function_name=%s ", function_name.c_str()); mexEvalString("drawnow;");
+            mexPrintf("function_name=%s ", function_name.c_str());
+            mexEvalString("drawnow;");
 #endif
-            int nb_input_arguments{fc->get_nb_input_arguments()};
+            int nb_input_arguments {fc->get_nb_input_arguments()};
 #ifdef DEBUG
-            mexPrintf("nb_input_arguments=%d ", nb_input_arguments); mexEvalString("drawnow;");
+            mexPrintf("nb_input_arguments=%d ", nb_input_arguments);
+            mexEvalString("drawnow;");
 #endif
-            int nb_output_arguments{fc->get_nb_output_arguments()};
+            int nb_output_arguments {fc->get_nb_output_arguments()};
 #ifdef DEBUG
-            mexPrintf("nb_output_arguments=%d\n", nb_output_arguments); mexEvalString("drawnow;");
+            mexPrintf("nb_output_arguments=%d\n", nb_output_arguments);
+            mexEvalString("drawnow;");
 #endif
 
-            mxArray *output_arguments[3];
+            mxArray* output_arguments[3];
             string arg_func_name = fc->get_arg_func_name();
 #ifdef DEBUG
             mexPrintf("arg_func_name.length() = %d\n", arg_func_name.length());
             mexPrintf("arg_func_name.c_str() = %s\n", arg_func_name.c_str());
 #endif
-            int nb_add_input_arguments{fc->get_nb_add_input_arguments()};
+            int nb_add_input_arguments {fc->get_nb_add_input_arguments()};
             call_type = fc->get_call_type();
 #ifdef DEBUG
-            mexPrintf("call_type=%d ExternalFunctionCallTypeWithoutDerivative=%d\n", call_type, ExternalFunctionCallType::levelWithoutDerivative);
+            mexPrintf("call_type=%d ExternalFunctionCallTypeWithoutDerivative=%d\n", call_type,
+                      ExternalFunctionCallType::levelWithoutDerivative);
             mexEvalString("drawnow;");
 #endif
-            mxArray **input_arguments;
+            mxArray** input_arguments;
             switch (call_type)
               {
               case ExternalFunctionCallType::levelWithoutDerivative:
               case ExternalFunctionCallType::levelWithFirstDerivative:
               case ExternalFunctionCallType::levelWithFirstAndSecondDerivative:
                 {
-                  input_arguments = static_cast<mxArray **>(mxMalloc(nb_input_arguments * sizeof(mxArray *)));
-                  test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, nb_input_arguments * sizeof(mxArray *));
+                  input_arguments
+                      = static_cast<mxArray**>(mxMalloc(nb_input_arguments * sizeof(mxArray*)));
+                  test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__,
+                                nb_input_arguments * sizeof(mxArray*));
 #ifdef DEBUG
                   mexPrintf("Stack.size()=%d\n", Stack.size());
                   mexEvalString("drawnow;");
 #endif
-                  for (int i{0}; i < nb_input_arguments; i++)
+                  for (int i {0}; i < nb_input_arguments; i++)
                     {
-                      mxArray *vv = mxCreateDoubleScalar(Stack.top());
+                      mxArray* vv = mxCreateDoubleScalar(Stack.top());
                       input_arguments[nb_input_arguments - i - 1] = vv;
                       Stack.pop();
                     }
-                  if (mexCallMATLAB(nb_output_arguments, output_arguments, nb_input_arguments, input_arguments, function_name.c_str()))
-                    throw FatalException{"External function: " + function_name + " not found"};
+                  if (mexCallMATLAB(nb_output_arguments, output_arguments, nb_input_arguments,
+                                    input_arguments, function_name.c_str()))
+                    throw FatalException {"External function: " + function_name + " not found"};
 
-                  double *rr = mxGetPr(output_arguments[0]);
+                  double* rr = mxGetPr(output_arguments[0]);
                   Stack.push(*rr);
                   if (call_type == ExternalFunctionCallType::levelWithFirstDerivative
                       || call_type == ExternalFunctionCallType::levelWithFirstAndSecondDerivative)
                     {
-                      int indx{fc->get_indx()};
-                      double *FD1 = mxGetPr(output_arguments[1]);
+                      int indx {fc->get_indx()};
+                      double* FD1 = mxGetPr(output_arguments[1]);
                       size_t rows = mxGetN(output_arguments[1]);
-                      for (int i{0}; i < static_cast<int>(rows); i++)
-                        TEFD[{ indx, i }] = FD1[i];
+                      for (int i {0}; i < static_cast<int>(rows); i++)
+                        TEFD[{indx, i}] = FD1[i];
                     }
                   if (call_type == ExternalFunctionCallType::levelWithFirstAndSecondDerivative)
                     {
-                      int indx{fc->get_indx()};
-                      double *FD2 = mxGetPr(output_arguments[2]);
+                      int indx {fc->get_indx()};
+                      double* FD2 = mxGetPr(output_arguments[2]);
                       size_t rows = mxGetM(output_arguments[2]);
                       size_t cols = mxGetN(output_arguments[2]);
-                      int k{0};
-                      for (int j{0}; j < static_cast<int>(cols); j++)
-                        for (int i{0}; i < static_cast<int>(rows); i++)
-                          TEFDD[{ indx, i, j }] = FD2[k++];
+                      int k {0};
+                      for (int j {0}; j < static_cast<int>(cols); j++)
+                        for (int i {0}; i < static_cast<int>(rows); i++)
+                          TEFDD[{indx, i, j}] = FD2[k++];
                     }
                 }
                 break;
               case ExternalFunctionCallType::numericalFirstDerivative:
                 {
-                  input_arguments = static_cast<mxArray **>(mxMalloc((nb_input_arguments+1+nb_add_input_arguments) * sizeof(mxArray *)));
-                  test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, (nb_input_arguments+1+nb_add_input_arguments) * sizeof(mxArray *));
-                  mxArray *vv = mxCreateString(arg_func_name.c_str());
+                  input_arguments = static_cast<mxArray**>(mxMalloc(
+                      (nb_input_arguments + 1 + nb_add_input_arguments) * sizeof(mxArray*)));
+                  test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__,
+                                (nb_input_arguments + 1 + nb_add_input_arguments)
+                                    * sizeof(mxArray*));
+                  mxArray* vv = mxCreateString(arg_func_name.c_str());
                   input_arguments[0] = vv;
                   vv = mxCreateDoubleScalar(fc->get_row());
                   input_arguments[1] = vv;
@@ -1976,10 +2021,10 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
 #ifdef DEBUG
                       mexPrintf("i=%d rr = %f Stack.size()=%d\n", i, rr, Stack.size());
 #endif
-                      mxSetCell(vv, nb_add_input_arguments - (i+1), mxCreateDoubleScalar(rr));
+                      mxSetCell(vv, nb_add_input_arguments - (i + 1), mxCreateDoubleScalar(rr));
                       Stack.pop();
                     }
-                  input_arguments[nb_input_arguments+nb_add_input_arguments] = vv;
+                  input_arguments[nb_input_arguments + nb_add_input_arguments] = vv;
 #ifdef DEBUG
                   mexCallMATLAB(0, nullptr, 1, &input_arguments[0], "disp");
                   mexCallMATLAB(0, nullptr, 1, &input_arguments[1], "disp");
@@ -1988,9 +2033,10 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                   mexEvalString("drawnow;");
 #endif
                   nb_input_arguments = 3;
-                  if (mexCallMATLAB(nb_output_arguments, output_arguments, nb_input_arguments, input_arguments, function_name.c_str()))
-                    throw FatalException{"External function: " + function_name + " not found"};
-                  double *rr = mxGetPr(output_arguments[0]);
+                  if (mexCallMATLAB(nb_output_arguments, output_arguments, nb_input_arguments,
+                                    input_arguments, function_name.c_str()))
+                    throw FatalException {"External function: " + function_name + " not found"};
+                  double* rr = mxGetPr(output_arguments[0]);
 #ifdef DEBUG
                   mexPrintf("*rr=%f\n", *rr);
 #endif
@@ -1999,35 +2045,41 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                 break;
               case ExternalFunctionCallType::separatelyProvidedFirstDerivative:
                 {
-                  input_arguments = static_cast<mxArray **>(mxMalloc(nb_input_arguments * sizeof(mxArray *)));
-                  test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, nb_input_arguments * sizeof(mxArray *));
-                  for (int i{0}; i < nb_input_arguments; i++)
+                  input_arguments
+                      = static_cast<mxArray**>(mxMalloc(nb_input_arguments * sizeof(mxArray*)));
+                  test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__,
+                                nb_input_arguments * sizeof(mxArray*));
+                  for (int i {0}; i < nb_input_arguments; i++)
                     {
-                      mxArray *vv = mxCreateDoubleScalar(Stack.top());
+                      mxArray* vv = mxCreateDoubleScalar(Stack.top());
                       input_arguments[(nb_input_arguments - 1) - i] = vv;
                       Stack.pop();
                     }
-                  if (mexCallMATLAB(nb_output_arguments, output_arguments, nb_input_arguments, input_arguments, function_name.c_str()))
-                    throw FatalException{"External function: " + function_name + " not found"};
-                  int indx{fc->get_indx()};
-                  double *FD1 = mxGetPr(output_arguments[0]);
+                  if (mexCallMATLAB(nb_output_arguments, output_arguments, nb_input_arguments,
+                                    input_arguments, function_name.c_str()))
+                    throw FatalException {"External function: " + function_name + " not found"};
+                  int indx {fc->get_indx()};
+                  double* FD1 = mxGetPr(output_arguments[0]);
                   size_t rows = mxGetN(output_arguments[0]);
-                  for (int i{0}; i < static_cast<int>(rows); i++)
-                    TEFD[{ indx, i }] = FD1[i];
+                  for (int i {0}; i < static_cast<int>(rows); i++)
+                    TEFD[{indx, i}] = FD1[i];
                 }
                 break;
               case ExternalFunctionCallType::numericalSecondDerivative:
                 {
-                  input_arguments = static_cast<mxArray **>(mxMalloc((nb_input_arguments+1+nb_add_input_arguments) * sizeof(mxArray *)));
-                  test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, (nb_input_arguments+1+nb_add_input_arguments) * sizeof(mxArray *));
-                  mxArray *vv = mxCreateString(arg_func_name.c_str());
+                  input_arguments = static_cast<mxArray**>(mxMalloc(
+                      (nb_input_arguments + 1 + nb_add_input_arguments) * sizeof(mxArray*)));
+                  test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__,
+                                (nb_input_arguments + 1 + nb_add_input_arguments)
+                                    * sizeof(mxArray*));
+                  mxArray* vv = mxCreateString(arg_func_name.c_str());
                   input_arguments[0] = vv;
                   vv = mxCreateDoubleScalar(fc->get_row());
                   input_arguments[1] = vv;
                   vv = mxCreateDoubleScalar(fc->get_col());
                   input_arguments[2] = vv;
                   vv = mxCreateCellMatrix(1, nb_add_input_arguments);
-                  for (int i{0}; i < nb_add_input_arguments; i++)
+                  for (int i {0}; i < nb_add_input_arguments; i++)
                     {
                       double rr = Stack.top();
 #ifdef DEBUG
@@ -2036,7 +2088,7 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                       mxSetCell(vv, (nb_add_input_arguments - 1) - i, mxCreateDoubleScalar(rr));
                       Stack.pop();
                     }
-                  input_arguments[nb_input_arguments+nb_add_input_arguments] = vv;
+                  input_arguments[nb_input_arguments + nb_add_input_arguments] = vv;
 #ifdef DEBUG
                   mexCallMATLAB(0, nullptr, 1, &input_arguments[0], "disp");
                   mexCallMATLAB(0, nullptr, 1, &input_arguments[1], "disp");
@@ -2045,73 +2097,77 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
                   mexEvalString("drawnow;");
 #endif
                   nb_input_arguments = 3;
-                  if (mexCallMATLAB(nb_output_arguments, output_arguments, nb_input_arguments, input_arguments, function_name.c_str()))
-                    throw FatalException{"External function: " + function_name + " not found"};
-                  double *rr = mxGetPr(output_arguments[0]);
+                  if (mexCallMATLAB(nb_output_arguments, output_arguments, nb_input_arguments,
+                                    input_arguments, function_name.c_str()))
+                    throw FatalException {"External function: " + function_name + " not found"};
+                  double* rr = mxGetPr(output_arguments[0]);
                   Stack.push(*rr);
                 }
                 break;
               case ExternalFunctionCallType::separatelyProvidedSecondDerivative:
                 {
-                  input_arguments = static_cast<mxArray **>(mxMalloc(nb_input_arguments * sizeof(mxArray *)));
-                  test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__, nb_input_arguments * sizeof(mxArray *));
-                  for (int i{0}; i < nb_input_arguments; i++)
+                  input_arguments
+                      = static_cast<mxArray**>(mxMalloc(nb_input_arguments * sizeof(mxArray*)));
+                  test_mxMalloc(input_arguments, __LINE__, __FILE__, __func__,
+                                nb_input_arguments * sizeof(mxArray*));
+                  for (int i {0}; i < nb_input_arguments; i++)
                     {
-                      mxArray *vv = mxCreateDoubleScalar(Stack.top());
+                      mxArray* vv = mxCreateDoubleScalar(Stack.top());
                       input_arguments[i] = vv;
                       Stack.pop();
                     }
-                  if (mexCallMATLAB(nb_output_arguments, output_arguments, nb_input_arguments, input_arguments, function_name.c_str()))
-                    throw FatalException{"External function: " + function_name + " not found"};
-                  int indx{fc->get_indx()};
-                  double *FD2 = mxGetPr(output_arguments[2]);
+                  if (mexCallMATLAB(nb_output_arguments, output_arguments, nb_input_arguments,
+                                    input_arguments, function_name.c_str()))
+                    throw FatalException {"External function: " + function_name + " not found"};
+                  int indx {fc->get_indx()};
+                  double* FD2 = mxGetPr(output_arguments[2]);
                   size_t rows = mxGetM(output_arguments[0]);
                   size_t cols = mxGetN(output_arguments[0]);
-                  int k{0};
-                  for (int j{0}; j < static_cast<int>(cols); j++)
-                    for (int i{0}; i < static_cast<int>(rows); i++)
-                      TEFDD[{ indx, i, j }] = FD2[k++];
+                  int k {0};
+                  for (int j {0}; j < static_cast<int>(cols); j++)
+                    for (int i {0}; i < static_cast<int>(rows); i++)
+                      TEFDD[{indx, i, j}] = FD2[k++];
                 }
                 break;
               }
           }
           break;
         case Tags::FSTPTEF:
-          var = static_cast<FSTPTEF_ *>(*it_code)->get_number();
+          var = static_cast<FSTPTEF_*>(*it_code)->get_number();
 #ifdef DEBUG
           mexPrintf("FSTPTEF\n");
           mexPrintf("var=%d Stack.size()=%d\n", var, Stack.size());
 #endif
-          TEF[var-1] = Stack.top();
+          TEF[var - 1] = Stack.top();
 #ifdef DEBUG
-          mexPrintf("FSTP TEF[var-1]=%f done\n", TEF[var-1]);
+          mexPrintf("FSTP TEF[var-1]=%f done\n", TEF[var - 1]);
           mexEvalString("drawnow;");
 #endif
           Stack.pop();
           break;
         case Tags::FLDTEF:
-          var = static_cast<FLDTEF_ *>(*it_code)->get_number();
+          var = static_cast<FLDTEF_*>(*it_code)->get_number();
 #ifdef DEBUG
           mexPrintf("FLDTEF\n");
           mexPrintf("var=%d Stack.size()=%d\n", var, Stack.size());
-          mexPrintf("FLD TEF[var-1]=%f done\n", TEF[var-1]);
+          mexPrintf("FLD TEF[var-1]=%f done\n", TEF[var - 1]);
           mexEvalString("drawnow;");
 #endif
-          Stack.push(TEF[var-1]);
+          Stack.push(TEF[var - 1]);
           break;
         case Tags::FSTPTEFD:
           {
-            int indx{static_cast<FSTPTEFD_ *>(*it_code)->get_indx()};
-            int row{static_cast<FSTPTEFD_ *>(*it_code)->get_row()};
+            int indx {static_cast<FSTPTEFD_*>(*it_code)->get_indx()};
+            int row {static_cast<FSTPTEFD_*>(*it_code)->get_row()};
 #ifdef DEBUG
             mexPrintf("FSTPTEFD\n");
             mexPrintf("indx=%d Stack.size()=%d\n", indx, Stack.size());
 #endif
             if (call_type == ExternalFunctionCallType::numericalFirstDerivative)
               {
-                TEFD[{ indx, row-1 }] = Stack.top();
+                TEFD[{indx, row - 1}] = Stack.top();
 #ifdef DEBUG
-                mexPrintf("FSTP TEFD[{ indx, row }]=%f done\n", TEFD[{ indx, row-1 }]);
+                mexPrintf("FSTP TEFD[{ indx, row }]=%f done\n", TEFD[{indx, row - 1}]);
                 mexEvalString("drawnow;");
 #endif
                 Stack.pop();
@@ -2121,31 +2177,32 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           break;
         case Tags::FLDTEFD:
           {
-            int indx{static_cast<FLDTEFD_ *>(*it_code)->get_indx()};
-            int row{static_cast<FLDTEFD_ *>(*it_code)->get_row()};
+            int indx {static_cast<FLDTEFD_*>(*it_code)->get_indx()};
+            int row {static_cast<FLDTEFD_*>(*it_code)->get_row()};
 #ifdef DEBUG
             mexPrintf("FLDTEFD\n");
             mexPrintf("indx=%d row=%d Stack.size()=%d\n", indx, row, Stack.size());
-            mexPrintf("FLD TEFD[{ indx, row }]=%f done\n", TEFD[{ indx, row-1 }]);
+            mexPrintf("FLD TEFD[{ indx, row }]=%f done\n", TEFD[{indx, row - 1}]);
             mexEvalString("drawnow;");
 #endif
-            Stack.push(TEFD[{ indx, row-1 }]);
+            Stack.push(TEFD[{indx, row - 1}]);
           }
           break;
         case Tags::FSTPTEFDD:
           {
-            int indx{static_cast<FSTPTEFDD_ *>(*it_code)->get_indx()};
-            int row{static_cast<FSTPTEFDD_ *>(*it_code)->get_row()};
-            int col{static_cast<FSTPTEFDD_ *>(*it_code)->get_col()};
+            int indx {static_cast<FSTPTEFDD_*>(*it_code)->get_indx()};
+            int row {static_cast<FSTPTEFDD_*>(*it_code)->get_row()};
+            int col {static_cast<FSTPTEFDD_*>(*it_code)->get_col()};
 #ifdef DEBUG
             mexPrintf("FSTPTEFD\n");
             mexPrintf("indx=%d Stack.size()=%d\n", indx, Stack.size());
 #endif
             if (call_type == ExternalFunctionCallType::numericalSecondDerivative)
               {
-                TEFDD[{ indx, row-1, col-1 }] = Stack.top();
+                TEFDD[{indx, row - 1, col - 1}] = Stack.top();
 #ifdef DEBUG
-                mexPrintf("FSTP TEFDD[{ indx, row-1, col-1 }]=%f done\n", TEFDD[{ indx, row-1, col-1 }]);
+                mexPrintf("FSTP TEFDD[{ indx, row-1, col-1 }]=%f done\n",
+                          TEFDD[{indx, row - 1, col - 1}]);
                 mexEvalString("drawnow;");
 #endif
                 Stack.pop();
@@ -2155,20 +2212,21 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           break;
         case Tags::FLDTEFDD:
           {
-            int indx{static_cast<FLDTEFDD_ *>(*it_code)->get_indx()};
-            int row{static_cast<FLDTEFDD_ *>(*it_code)->get_row()};
-            int col{static_cast<FSTPTEFDD_ *>(*it_code)->get_col()};
+            int indx {static_cast<FLDTEFDD_*>(*it_code)->get_indx()};
+            int row {static_cast<FLDTEFDD_*>(*it_code)->get_row()};
+            int col {static_cast<FSTPTEFDD_*>(*it_code)->get_col()};
 #ifdef DEBUG
             mexPrintf("FLDTEFD\n");
             mexPrintf("indx=%d Stack.size()=%d\n", indx, Stack.size());
-            mexPrintf("FLD TEFD[{ indx, row-1, col-1 }]=%f done\n", TEFDD[{ indx, row-1, col-1 }]);
+            mexPrintf("FLD TEFD[{ indx, row-1, col-1 }]=%f done\n",
+                      TEFDD[{indx, row - 1, col - 1}]);
             mexEvalString("drawnow;");
 #endif
-            Stack.push(TEFDD[{ indx, row-1, col-1 }]);
+            Stack.push(TEFDD[{indx, row - 1, col - 1}]);
           }
           break;
         case Tags::FENDBLOCK:
-          //it's the block end
+          // it's the block end
 #ifdef DEBUG
           mexPrintf("FENDBLOCK\n");
 #endif
@@ -2185,21 +2243,22 @@ Evaluate::evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size,
           if (evaluate)
             {
 #ifdef DEBUG
-              mexPrintf("FJMPIFEVAL length=%d\n", static_cast<FJMPIFEVAL_ *>(*it_code)->get_pos());
+              mexPrintf("FJMPIFEVAL length=%d\n", static_cast<FJMPIFEVAL_*>(*it_code)->get_pos());
               mexEvalString("drawnow;");
 #endif
-              it_code += static_cast<FJMPIFEVAL_ *>(*it_code)->get_pos() /* - 1*/;
+              it_code += static_cast<FJMPIFEVAL_*>(*it_code)->get_pos() /* - 1*/;
             }
           break;
         case Tags::FJMP:
 #ifdef DEBUG
-          mexPrintf("FJMP length=%d\n", static_cast<FJMP_ *>(*it_code)->get_pos());
+          mexPrintf("FJMP length=%d\n", static_cast<FJMP_*>(*it_code)->get_pos());
           mexEvalString("drawnow;");
 #endif
-          it_code += static_cast<FJMP_ *>(*it_code)->get_pos() /*- 1 */;
+          it_code += static_cast<FJMP_*>(*it_code)->get_pos() /*- 1 */;
           break;
         default:
-          throw FatalException{"In compute_block_time, unknown opcode " + to_string(static_cast<int>((*it_code)->op_code))};
+          throw FatalException {"In compute_block_time, unknown opcode "
+                                + to_string(static_cast<int>((*it_code)->op_code))};
         }
       it_code++;
     }
@@ -2214,7 +2273,7 @@ Evaluate::gotoBlock(int block)
 {
   block_num = block;
 
-  auto *fb {currentBlockTag()};
+  auto* fb {currentBlockTag()};
   if (fb->op_code != Tags::FBEGINBLOCK)
     throw FatalException {"Evaluate::gotoBlock: internal inconsistency"};
 
@@ -2224,8 +2283,8 @@ Evaluate::gotoBlock(int block)
 void
 Evaluate::printCurrentBlock()
 {
-  auto it_code { currentBlockBeginning() };
-  mexPrintf("\nBlock %d\n", block_num+1);
+  auto it_code {currentBlockBeginning()};
+  mexPrintf("\nBlock %d\n", block_num + 1);
   mexPrintf("----------\n");
   bool go_on {true};
   bool space {false};
@@ -2258,19 +2317,21 @@ Evaluate::printCurrentBlock()
 int
 Evaluate::getNumberOfTemporaryTerms() const
 {
-  BytecodeInstruction *instr {instructions_list.front()};
+  BytecodeInstruction* instr {instructions_list.front()};
   if (steady_state)
     {
       if (instr->op_code == Tags::FDIMST)
-        return reinterpret_cast<FDIMST_ *>(instr)->get_size();
+        return reinterpret_cast<FDIMST_*>(instr)->get_size();
       else
-        throw FatalException {"Evaluate::getNumberOfTemporaryTerms: static .cod file does not begin with FDIMST!"};
+        throw FatalException {
+            "Evaluate::getNumberOfTemporaryTerms: static .cod file does not begin with FDIMST!"};
     }
   else
     {
       if (instr->op_code == Tags::FDIMT)
-        return reinterpret_cast<FDIMT_ *>(instr)->get_size();
+        return reinterpret_cast<FDIMT_*>(instr)->get_size();
       else
-        throw FatalException {"Evaluate::getNumberOfTemporaryTerms: dynamic .cod file does not begin with FDIMT!"};
+        throw FatalException {
+            "Evaluate::getNumberOfTemporaryTerms: dynamic .cod file does not begin with FDIMT!"};
     }
 }
diff --git a/mex/sources/bytecode/Evaluate.hh b/mex/sources/bytecode/Evaluate.hh
index bd18bba68a39d74fcc5100610347735db4880072..9b870f0a1c5a9858597b4bdd2619780d1a9ce4a9 100644
--- a/mex/sources/bytecode/Evaluate.hh
+++ b/mex/sources/bytecode/Evaluate.hh
@@ -20,24 +20,24 @@
 #ifndef _EVALUATE_HH
 #define _EVALUATE_HH
 
-#include <vector>
-#include <string>
+#include <deque>
+#include <filesystem>
 #include <map>
-#include <optional>
 #include <memory>
-#include <filesystem>
-#include <deque>
+#include <optional>
+#include <string>
+#include <vector>
 
-#include "Bytecode.hh"
 #include "BasicSymbolTable.hh"
+#include "Bytecode.hh"
 
 class Evaluate
 {
 private:
-  using instructions_list_t = vector<BytecodeInstruction *>;
+  using instructions_list_t = vector<BytecodeInstruction*>;
   using it_code_type = instructions_list_t::const_iterator;
 
-  const BasicSymbolTable &symbol_table;
+  const BasicSymbolTable& symbol_table;
   const bool steady_state; // Whether this is a static or dynamic .cod file
 
   // Memory copy of the contents of the .cod file
@@ -55,14 +55,14 @@ private:
      Those are either pointers inside “raw_bytecode” or “deserialized_{fbeginblock,fcall}” */
   instructions_list_t instructions_list;
 
-   // Number of blocks in the model
+  // Number of blocks in the model
   int nb_blocks {0};
 
   // Index of beginnings of blocks within instructions_list
   vector<size_t> begin_block;
 
   int block_num; // Index of the current block
-  int size; // Size of the current block
+  int size;      // Size of the current block
 
   ExpressionType EQN_type;
   int EQN_equation, EQN_dvar1;
@@ -75,12 +75,14 @@ private:
      the expression that created a floating point exception, in which case the
      corresponding mathematical operator will be printed within braces.
      The second output argument points to the tag past the expression. */
-  pair<string, it_code_type> print_expression(const it_code_type &expr_begin, const optional<it_code_type> &faulty_op = nullopt) const;
+  pair<string, it_code_type> print_expression(const it_code_type& expr_begin,
+                                              const optional<it_code_type>& faulty_op
+                                              = nullopt) const;
 
-  FBEGINBLOCK_ *
+  FBEGINBLOCK_*
   currentBlockTag() const
   {
-    return reinterpret_cast<FBEGINBLOCK_ *>(instructions_list[begin_block[block_num]]);
+    return reinterpret_cast<FBEGINBLOCK_*>(instructions_list[begin_block[block_num]]);
   }
 
   // Returns iterator to first instruction in the current block (after FBEGINBLOCK)
@@ -91,9 +93,17 @@ private:
   }
 
 public:
-  Evaluate(const filesystem::path &codfile, bool steady_state_arg, const BasicSymbolTable &symbol_table_arg);
-
-  void evaluateBlock(int it_, int y_kmin, double *__restrict__ y, int y_size, double *__restrict__ x, int nb_row_x, double *__restrict__ params, const double *__restrict__ steady_y, double *__restrict__ u, int Per_u_, double *__restrict__ T, int T_nrows, map<int, double> &TEF, map<pair<int, int>, double> &TEFD, map<tuple<int, int, int>, double> &TEFDD, double *__restrict__ r, double *__restrict__ g1, double *__restrict__ jacob, double *__restrict__ jacob_exo, double *__restrict__ jacob_exo_det, bool evaluate, bool no_derivatives);
+  Evaluate(const filesystem::path& codfile, bool steady_state_arg,
+           const BasicSymbolTable& symbol_table_arg);
+
+  void evaluateBlock(int it_, int y_kmin, double* __restrict__ y, int y_size,
+                     double* __restrict__ x, int nb_row_x, double* __restrict__ params,
+                     const double* __restrict__ steady_y, double* __restrict__ u, int Per_u_,
+                     double* __restrict__ T, int T_nrows, map<int, double>& TEF,
+                     map<pair<int, int>, double>& TEFD, map<tuple<int, int, int>, double>& TEFDD,
+                     double* __restrict__ r, double* __restrict__ g1, double* __restrict__ jacob,
+                     double* __restrict__ jacob_exo, double* __restrict__ jacob_exo_det,
+                     bool evaluate, bool no_derivatives);
 
   // Prints current block
   void printCurrentBlock();
diff --git a/mex/sources/bytecode/Interpreter.cc b/mex/sources/bytecode/Interpreter.cc
index 452ece6ccfba1462cf976f752948058467e52627..a9edd5930c90dde33a4ec71e204624b0448b0f73 100644
--- a/mex/sources/bytecode/Interpreter.cc
+++ b/mex/sources/bytecode/Interpreter.cc
@@ -17,37 +17,34 @@
  * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#include <sstream>
 #include <algorithm>
-#include <filesystem>
-#include <numeric>
+#include <cassert>
 #include <cfenv>
-#include <type_traits>
 #include <chrono>
+#include <filesystem>
 #include <limits>
-#include <cassert>
+#include <numeric>
+#include <sstream>
+#include <type_traits>
 
 #include "Interpreter.hh"
 
 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, int y_size_arg,
+Interpreter::Interpreter(Evaluate& evaluator_arg, double* params_arg, double* y_arg, double* ya_arg,
+                         double* x_arg, double* steady_y_arg, double* direction_arg, int y_size_arg,
                          int nb_row_x_arg, int periods_arg, int y_kmin_arg, int y_kmax_arg,
                          int maxit_arg_, double solve_tolf_arg, double markowitz_c_arg,
-                         int minimal_solving_periods_arg, int stack_solve_algo_arg, int solve_algo_arg,
-                         bool print_arg, const mxArray *GlobalTemporaryTerms_arg,
-                         bool steady_state_arg, bool block_decomposed_arg, int col_x_arg, int col_y_arg, const BasicSymbolTable &symbol_table_arg, int verbosity_arg) :
-  symbol_table {symbol_table_arg},
-  steady_state {steady_state_arg},
-  block_decomposed {block_decomposed_arg},
-  evaluator {evaluator_arg},
-  minimal_solving_periods {minimal_solving_periods_arg},
-  y_size {y_size_arg},
-  y_kmin {y_kmin_arg},
-  y_kmax {y_kmax_arg},
-  periods {periods_arg},
-  verbosity {verbosity_arg}
+                         int minimal_solving_periods_arg, int stack_solve_algo_arg,
+                         int solve_algo_arg, bool print_arg,
+                         const mxArray* GlobalTemporaryTerms_arg, bool steady_state_arg,
+                         bool block_decomposed_arg, int col_x_arg, int col_y_arg,
+                         const BasicSymbolTable& symbol_table_arg, int verbosity_arg) :
+    symbol_table {symbol_table_arg},
+    steady_state {steady_state_arg},
+    block_decomposed {block_decomposed_arg}, evaluator {evaluator_arg},
+    minimal_solving_periods {minimal_solving_periods_arg}, y_size {y_size_arg}, y_kmin {y_kmin_arg},
+    y_kmax {y_kmax_arg}, periods {periods_arg}, verbosity {verbosity_arg}
 {
   pivotva = nullptr;
   mem_mngr.init_Mem();
@@ -82,13 +79,13 @@ Interpreter::Interpreter(Evaluate &evaluator_arg, double *params_arg, double *y_
   col_x = col_x_arg;
   col_y = col_y_arg;
 
-  int ntt { evaluator.getNumberOfTemporaryTerms() };
+  int ntt {evaluator.getNumberOfTemporaryTerms()};
   if (GlobalTemporaryTerms_arg)
     {
       if (steady_state)
         assert(ntt == static_cast<int>(mxGetNumberOfElements(GlobalTemporaryTerms_arg)));
       else
-        assert(periods*ntt == static_cast<int>(mxGetNumberOfElements(GlobalTemporaryTerms_arg)));
+        assert(periods * ntt == static_cast<int>(mxGetNumberOfElements(GlobalTemporaryTerms_arg)));
       GlobalTemporaryTerms = mxDuplicateArray(GlobalTemporaryTerms_arg);
     }
   else
@@ -110,13 +107,13 @@ Interpreter::evaluate_over_periods(bool forward)
     {
       if (forward)
         {
-          for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
+          for (it_ = y_kmin; it_ < periods + y_kmin; it_++)
             compute_block_time(0, false, false);
-          it_ = periods+y_kmin-1; // Do not leave it_ in inconsistent state
+          it_ = periods + y_kmin - 1; // Do not leave it_ in inconsistent state
         }
       else
         {
-          for (it_ = periods+y_kmin-1; it_ >= y_kmin; it_--)
+          for (it_ = periods + y_kmin - 1; it_ >= y_kmin; it_--)
             compute_block_time(0, false, false);
           it_ = y_kmin; // Do not leave it_ in inconsistent state (see #1727)
         }
@@ -133,7 +130,7 @@ Interpreter::solve_simple_one_periods()
   res1 = 0;
   while (!(cvg || iter >= maxit_))
     {
-      Per_y_ = it_*y_size;
+      Per_y_ = it_ * y_size;
       ya = y[Block_Contain[0].Variable + Per_y_];
       compute_block_time(0, false, false);
       if (!isfinite(res1))
@@ -153,7 +150,7 @@ Interpreter::solve_simple_one_periods()
                     {
                       res1 = numeric_limits<double>::quiet_NaN();
                       if (verbosity >= 1)
-                        mexPrintf("      Singularity in block %d", block_num+1);
+                        mexPrintf("      Singularity in block %d", block_num + 1);
                     }
                 }
             }
@@ -169,21 +166,22 @@ Interpreter::solve_simple_one_periods()
         {
           res1 = numeric_limits<double>::quiet_NaN();
           if (verbosity >= 1)
-            mexPrintf("      Singularity in block %d", block_num+1);
+            mexPrintf("      Singularity in block %d", block_num + 1);
         }
       iter++;
     }
   if (!cvg)
-    throw FatalException{"In Solve Forward simple, convergence not achieved in block "
-                         + to_string(block_num+1) + ", after " + to_string(iter) + " iterations"};
+    throw FatalException {"In Solve Forward simple, convergence not achieved in block "
+                          + to_string(block_num + 1) + ", after " + to_string(iter)
+                          + " iterations"};
 }
 
 void
 Interpreter::solve_simple_over_periods(bool forward)
 {
-  g1 = static_cast<double *>(mxMalloc(sizeof(double)));
+  g1 = static_cast<double*>(mxMalloc(sizeof(double)));
   test_mxMalloc(g1, __LINE__, __FILE__, __func__, sizeof(double));
-  r = static_cast<double *>(mxMalloc(sizeof(double)));
+  r = static_cast<double*>(mxMalloc(sizeof(double)));
   test_mxMalloc(r, __LINE__, __FILE__, __func__, sizeof(double));
   if (steady_state)
     {
@@ -194,13 +192,13 @@ Interpreter::solve_simple_over_periods(bool forward)
     {
       if (forward)
         {
-          for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
+          for (it_ = y_kmin; it_ < periods + y_kmin; it_++)
             solve_simple_one_periods();
-          it_= periods+y_kmin-1; // Do not leave it_ in inconsistent state
+          it_ = periods + y_kmin - 1; // Do not leave it_ in inconsistent state
         }
       else
         {
-          for (it_ = periods+y_kmin-1; it_ >= y_kmin; it_--)
+          for (it_ = periods + y_kmin - 1; it_ >= y_kmin; it_--)
             solve_simple_one_periods();
           it_ = y_kmin; // Do not leave it_ in inconsistent state (see #1727)
         }
@@ -215,34 +213,34 @@ Interpreter::compute_complete_2b()
   res1 = 0;
   res2 = 0;
   max_res = 0;
-  for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
+  for (it_ = y_kmin; it_ < periods + y_kmin; it_++)
     {
-      Per_u_ = (it_-y_kmin)*u_count_int;
-      Per_y_ = it_*y_size;
-      int shift = (it_-y_kmin) * size;
+      Per_u_ = (it_ - y_kmin) * u_count_int;
+      Per_y_ = it_ * y_size;
+      int shift = (it_ - y_kmin) * size;
       compute_block_time(Per_u_, false, false);
       if (!(isnan(res1) || isinf(res1)))
         for (int i = 0; i < size; i++)
           {
             double rr;
             rr = r[i];
-            res[i+shift] = rr;
+            res[i + shift] = rr;
             if (max_res < fabs(rr))
               {
                 max_res = fabs(rr);
                 max_res_idx = i;
               }
-            res2 += rr*rr;
+            res2 += rr * rr;
             res1 += fabs(rr);
           }
       else
         return;
     }
-  it_ = periods+y_kmin-1; // Do not leave it_ in inconsistent state
+  it_ = periods + y_kmin - 1; // Do not leave it_ in inconsistent state
 }
 
 void
-Interpreter::evaluate_a_block(bool initialization, bool single_block, const string &bin_base_name)
+Interpreter::evaluate_a_block(bool initialization, bool single_block, const string& bin_base_name)
 {
   switch (type)
     {
@@ -255,28 +253,33 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
               residual[j] = y[Block_Contain[j].Variable] - ya[Block_Contain[j].Variable];
           else
             for (int j = 0; j < size; j++)
-              residual[Block_Contain[j].Equation] = y[Block_Contain[j].Variable] - ya[Block_Contain[j].Variable];
+              residual[Block_Contain[j].Equation]
+                  = y[Block_Contain[j].Variable] - ya[Block_Contain[j].Variable];
         }
       else
         {
-          for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
+          for (it_ = y_kmin; it_ < periods + y_kmin; it_++)
             {
-              Per_y_ = it_*y_size;
+              Per_y_ = it_ * y_size;
               compute_block_time(0, true, false);
               if (single_block)
                 for (int j = 0; j < size; j++)
-                  residual[(it_-y_kmin)*size+j] = y[it_*y_size+Block_Contain[j].Variable] - ya[it_*y_size+Block_Contain[j].Variable];
+                  residual[(it_ - y_kmin) * size + j]
+                      = y[it_ * y_size + Block_Contain[j].Variable]
+                        - ya[it_ * y_size + Block_Contain[j].Variable];
               else
                 for (int j = 0; j < size; j++)
-                  residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = y[it_*y_size+Block_Contain[j].Variable] - ya[it_*y_size+Block_Contain[j].Variable];
+                  residual[(it_ - y_kmin) * y_size + Block_Contain[j].Equation]
+                      = y[it_ * y_size + Block_Contain[j].Variable]
+                        - ya[it_ * y_size + Block_Contain[j].Variable];
             }
         }
       break;
     case BlockSimulationType::solveForwardSimple:
-      g1 = static_cast<double *>(mxMalloc(size*size*sizeof(double)));
-      test_mxMalloc(g1, __LINE__, __FILE__, __func__, size*size*sizeof(double));
-      r = static_cast<double *>(mxMalloc(size*sizeof(double)));
-      test_mxMalloc(r, __LINE__, __FILE__, __func__, size*sizeof(double));
+      g1 = static_cast<double*>(mxMalloc(size * size * sizeof(double)));
+      test_mxMalloc(g1, __LINE__, __FILE__, __func__, size * size * sizeof(double));
+      r = static_cast<double*>(mxMalloc(size * sizeof(double)));
+      test_mxMalloc(r, __LINE__, __FILE__, __func__, size * sizeof(double));
       if (steady_state)
         {
           compute_block_time(0, true, false);
@@ -289,16 +292,16 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
         }
       else
         {
-          for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
+          for (it_ = y_kmin; it_ < periods + y_kmin; it_++)
             {
-              Per_y_ = it_*y_size;
+              Per_y_ = it_ * y_size;
               compute_block_time(0, true, false);
               if (!single_block)
                 for (int j = 0; j < size; j++)
-                  residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = r[j];
+                  residual[(it_ - y_kmin) * y_size + Block_Contain[j].Equation] = r[j];
               else
                 for (int j = 0; j < size; j++)
-                  residual[(it_-y_kmin)*size+j] = r[j];
+                  residual[(it_ - y_kmin) * size + j] = r[j];
             }
         }
       mxFree(g1);
@@ -313,8 +316,8 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
 #ifdef DEBUG
       mexPrintf("in SOLVE FORWARD COMPLETE r = mxMalloc(%d*sizeof(double))\n", size);
 #endif
-      r = static_cast<double *>(mxMalloc(size*sizeof(double)));
-      test_mxMalloc(r, __LINE__, __FILE__, __func__, size*sizeof(double));
+      r = static_cast<double*>(mxMalloc(size * sizeof(double)));
+      test_mxMalloc(r, __LINE__, __FILE__, __func__, size * sizeof(double));
       if (steady_state)
         {
           compute_block_time(0, true, false);
@@ -327,16 +330,16 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
         }
       else
         {
-          for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
+          for (it_ = y_kmin; it_ < periods + y_kmin; it_++)
             {
-              Per_y_ = it_*y_size;
+              Per_y_ = it_ * y_size;
               compute_block_time(0, true, false);
               if (!single_block)
                 for (int j = 0; j < size; j++)
-                  residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = r[j];
+                  residual[(it_ - y_kmin) * y_size + Block_Contain[j].Equation] = r[j];
               else
                 for (int j = 0; j < size; j++)
-                  residual[(it_-y_kmin)*size+j] = r[j];
+                  residual[(it_ - y_kmin) * size + j] = r[j];
             }
         }
       mxFree(r);
@@ -350,28 +353,33 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
               residual[j] = y[Block_Contain[j].Variable] - ya[Block_Contain[j].Variable];
           else
             for (int j = 0; j < size; j++)
-              residual[Block_Contain[j].Equation] = y[Block_Contain[j].Variable] - ya[Block_Contain[j].Variable];
+              residual[Block_Contain[j].Equation]
+                  = y[Block_Contain[j].Variable] - ya[Block_Contain[j].Variable];
         }
       else
         {
-          for (it_ = periods+y_kmin-1; it_ >= y_kmin; it_--)
+          for (it_ = periods + y_kmin - 1; it_ >= y_kmin; it_--)
             {
-              Per_y_ = it_*y_size;
+              Per_y_ = it_ * y_size;
               compute_block_time(0, true, false);
               if (single_block)
                 for (int j = 0; j < size; j++)
-                  residual[(it_-y_kmin)*size+j] = y[it_*y_size+Block_Contain[j].Variable] - ya[it_*y_size+Block_Contain[j].Variable];
+                  residual[(it_ - y_kmin) * size + j]
+                      = y[it_ * y_size + Block_Contain[j].Variable]
+                        - ya[it_ * y_size + Block_Contain[j].Variable];
               else
                 for (int j = 0; j < size; j++)
-                  residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = y[it_*y_size+Block_Contain[j].Variable] - ya[it_*y_size+Block_Contain[j].Variable];
+                  residual[(it_ - y_kmin) * y_size + Block_Contain[j].Equation]
+                      = y[it_ * y_size + Block_Contain[j].Variable]
+                        - ya[it_ * y_size + Block_Contain[j].Variable];
             }
         }
       break;
     case BlockSimulationType::solveBackwardSimple:
-      g1 = static_cast<double *>(mxMalloc(size*size*sizeof(double)));
-      test_mxMalloc(g1, __LINE__, __FILE__, __func__, size*size*sizeof(double));
-      r = static_cast<double *>(mxMalloc(size*sizeof(double)));
-      test_mxMalloc(r, __LINE__, __FILE__, __func__, size*sizeof(double));
+      g1 = static_cast<double*>(mxMalloc(size * size * sizeof(double)));
+      test_mxMalloc(g1, __LINE__, __FILE__, __func__, size * size * sizeof(double));
+      r = static_cast<double*>(mxMalloc(size * sizeof(double)));
+      test_mxMalloc(r, __LINE__, __FILE__, __func__, size * sizeof(double));
       if (steady_state)
         {
           compute_block_time(0, true, false);
@@ -384,16 +392,16 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
         }
       else
         {
-          for (it_ = periods+y_kmin-1; it_ >= y_kmin; it_--)
+          for (it_ = periods + y_kmin - 1; it_ >= y_kmin; it_--)
             {
-              Per_y_ = it_*y_size;
+              Per_y_ = it_ * y_size;
               compute_block_time(0, true, false);
               if (!single_block)
                 for (int j = 0; j < size; j++)
-                  residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = r[j];
+                  residual[(it_ - y_kmin) * y_size + Block_Contain[j].Equation] = r[j];
               else
                 for (int j = 0; j < size; j++)
-                  residual[(it_-y_kmin)*size+j] = r[j];
+                  residual[(it_ - y_kmin) * size + j] = r[j];
             }
         }
       mxFree(g1);
@@ -405,8 +413,8 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
           fixe_u();
           Read_SparseMatrix(bin_base_name, false);
         }
-      r = static_cast<double *>(mxMalloc(size*sizeof(double)));
-      test_mxMalloc(r, __LINE__, __FILE__, __func__, size*sizeof(double));
+      r = static_cast<double*>(mxMalloc(size * sizeof(double)));
+      test_mxMalloc(r, __LINE__, __FILE__, __func__, size * sizeof(double));
       if (steady_state)
         {
           compute_block_time(0, true, false);
@@ -419,16 +427,16 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
         }
       else
         {
-          for (it_ = periods+y_kmin-1; it_ >= y_kmin; it_--)
+          for (it_ = periods + y_kmin - 1; it_ >= y_kmin; it_--)
             {
-              Per_y_ = it_*y_size;
+              Per_y_ = it_ * y_size;
               compute_block_time(0, true, false);
               if (!single_block)
                 for (int j = 0; j < size; j++)
-                  residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = r[j];
+                  residual[(it_ - y_kmin) * y_size + Block_Contain[j].Equation] = r[j];
               else
                 for (int j = 0; j < size; j++)
-                  residual[(it_-y_kmin)*size+j] = r[j];
+                  residual[(it_ - y_kmin) * size + j] = r[j];
             }
         }
       mxFree(r);
@@ -440,20 +448,20 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
           fixe_u();
           Read_SparseMatrix(bin_base_name, true);
         }
-      u_count = u_count_int*(periods+y_kmax+y_kmin);
-      r = static_cast<double *>(mxMalloc(size*sizeof(double)));
-      test_mxMalloc(r, __LINE__, __FILE__, __func__, size*sizeof(double));
-      for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
+      u_count = u_count_int * (periods + y_kmax + y_kmin);
+      r = static_cast<double*>(mxMalloc(size * sizeof(double)));
+      test_mxMalloc(r, __LINE__, __FILE__, __func__, size * sizeof(double));
+      for (it_ = y_kmin; it_ < periods + y_kmin; it_++)
         {
-          Per_u_ = (it_-y_kmin)*u_count_int;
-          Per_y_ = it_*y_size;
+          Per_u_ = (it_ - y_kmin) * u_count_int;
+          Per_y_ = it_ * y_size;
           compute_block_time(Per_u_, true, false);
           if (!single_block)
             for (int j = 0; j < size; j++)
-              residual[(it_-y_kmin)*y_size+Block_Contain[j].Equation] = r[j];
+              residual[(it_ - y_kmin) * y_size + Block_Contain[j].Equation] = r[j];
           else
             for (int j = 0; j < size; j++)
-              residual[(it_-y_kmin)*size+j] = r[j];
+              residual[(it_ - y_kmin) * size + j] = r[j];
         }
       mxFree(r);
       break;
@@ -461,14 +469,17 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
 }
 
 int
-Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_table_conditional_local, bool single_block, const string &bin_base_name)
+Interpreter::simulate_a_block(
+    const vector_table_conditional_local_type& vector_table_conditional_local, bool single_block,
+    const string& bin_base_name)
 {
   max_res = 0;
   max_res_idx = 0;
   bool cvg;
-  double *y_save;
+  double* y_save;
 #ifdef DEBUG
-  mexPrintf("simulate_a_block type = %d, periods=%d, y_kmin=%d, y_kmax=%d\n", type, periods, y_kmin, y_kmax);
+  mexPrintf("simulate_a_block type = %d, periods=%d, y_kmin=%d, y_kmax=%d\n", type, periods, y_kmin,
+            y_kmax);
   mexEvalString("drawnow;");
 #endif
   switch (type)
@@ -520,7 +531,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
       mxFree(u);
       mxFree(index_equa);
       mxFree(index_vara);
-      fill_n(direction, y_size*col_y, 0);
+      fill_n(direction, y_size * col_y, 0);
       End_Solver();
       break;
     case BlockSimulationType::solveBackwardComplete:
@@ -541,7 +552,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
 
       mxFree(index_equa);
       mxFree(index_vara);
-      fill_n(direction, y_size*col_y, 0);
+      fill_n(direction, y_size * col_y, 0);
       mxFree(u);
       End_Solver();
       break;
@@ -564,18 +575,19 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
           fixe_u();
           Read_SparseMatrix(bin_base_name, true);
         }
-      u_count = u_count_int*(periods+y_kmax+y_kmin);
-      r = static_cast<double *>(mxMalloc(size*sizeof(double)));
-      test_mxMalloc(r, __LINE__, __FILE__, __func__, size*sizeof(double));
-      res = static_cast<double *>(mxMalloc(size*periods*sizeof(double)));
-      test_mxMalloc(res, __LINE__, __FILE__, __func__, size*periods*sizeof(double));
-      y_save = static_cast<double *>(mxMalloc(y_size*sizeof(double)*(periods+y_kmax+y_kmin)));
-      test_mxMalloc(y_save, __LINE__, __FILE__, __func__, y_size*sizeof(double)*(periods+y_kmax+y_kmin));
+      u_count = u_count_int * (periods + y_kmax + y_kmin);
+      r = static_cast<double*>(mxMalloc(size * sizeof(double)));
+      test_mxMalloc(r, __LINE__, __FILE__, __func__, size * sizeof(double));
+      res = static_cast<double*>(mxMalloc(size * periods * sizeof(double)));
+      test_mxMalloc(res, __LINE__, __FILE__, __func__, size * periods * sizeof(double));
+      y_save
+          = static_cast<double*>(mxMalloc(y_size * sizeof(double) * (periods + y_kmax + y_kmin)));
+      test_mxMalloc(y_save, __LINE__, __FILE__, __func__,
+                    y_size * sizeof(double) * (periods + y_kmax + y_kmin));
       iter = 0;
-      if (!is_linear
-          || stack_solve_algo == 4) // On linear blocks, stack_solve_algo=4 may
-                                    // need more than one iteration to find the
-                                    // optimal (unitary!) path length
+      if (!is_linear || stack_solve_algo == 4) // On linear blocks, stack_solve_algo=4 may
+                                               // need more than one iteration to find the
+                                               // optimal (unitary!) path length
         {
           cvg = false;
           glambda2 = g0 = very_big;
@@ -587,16 +599,16 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
               res1 = 0;
               max_res = 0;
               max_res_idx = 0;
-              copy_n(y, y_size*(periods+y_kmax+y_kmin), y_save);
+              copy_n(y, y_size * (periods + y_kmax + y_kmin), y_save);
               if (vector_table_conditional_local.size())
-                for (auto & it1 : vector_table_conditional_local)
+                for (auto& it1 : vector_table_conditional_local)
                   if (it1.is_cond)
                     y[it1.var_endo + y_kmin * size] = it1.constrained_value;
               compute_complete_2b();
               if (!(isnan(res1) || isinf(res1)))
                 cvg = (max_res < solve_tolf);
               if (isnan(res1) || isinf(res1) || (stack_solve_algo == 4 && iter > 0))
-                copy_n(y_save, y_size*(periods+y_kmax+y_kmin), y);
+                copy_n(y_save, y_size * (periods + y_kmax + y_kmin), y);
               u_count = u_count_saved;
               int prev_iter = iter;
               Simulate_Newton_Two_Boundaries(cvg, vector_table_conditional_local);
@@ -610,21 +622,23 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
                 }
             }
           if (!cvg)
-            throw FatalException{"In Solve two boundaries, convergence not achieved in block "
-                + to_string(block_num+1) + ", after "
-                + to_string(iter) + " iterations"};
+            throw FatalException {"In Solve two boundaries, convergence not achieved in block "
+                                  + to_string(block_num + 1) + ", after " + to_string(iter)
+                                  + " iterations"};
         }
       else
         {
           res1 = 0;
           res2 = 0;
-          max_res = 0; max_res_idx = 0;
+          max_res = 0;
+          max_res_idx = 0;
 
           compute_complete_2b();
 
           cvg = false;
           Simulate_Newton_Two_Boundaries(cvg, vector_table_conditional_local);
-          max_res = 0; max_res_idx = 0;
+          max_res = 0;
+          max_res_idx = 0;
         }
       slowc = 1; // slowc is modified when stack_solve_algo=4, so restore it
       if (r)
@@ -639,40 +653,45 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
         mxFree(index_equa);
       if (res)
         mxFree(res);
-      fill_n(direction, y_size*col_y, 0);
+      fill_n(direction, y_size * col_y, 0);
       End_Solver();
       break;
     default:
-      throw FatalException{"In simulate_a_block, Unknown type = " + to_string(static_cast<int>(type))};
+      throw FatalException {"In simulate_a_block, Unknown type = "
+                            + to_string(static_cast<int>(type))};
       return ERROR_ON_EXIT;
     }
   return NO_ERROR_ON_EXIT;
 }
 
 void
-Interpreter::check_for_controlled_exo_validity(const vector<s_plan> &sconstrained_extended_path)
+Interpreter::check_for_controlled_exo_validity(const vector<s_plan>& sconstrained_extended_path)
 {
   vector<int> exogenous {evaluator.getCurrentBlockExogenous()};
   vector<int> endogenous {evaluator.getCurrentBlockEndogenous()};
-  for (auto & it : sconstrained_extended_path)
+  for (auto& it : sconstrained_extended_path)
     {
       if (find(endogenous.begin(), endogenous.end(), it.exo_num) != endogenous.end()
           && find(exogenous.begin(), exogenous.end(), it.var_num) == exogenous.end())
-        throw FatalException{"\nThe conditional forecast involving as constrained variable "
-            + symbol_table.getName(SymbolType::endogenous, it.exo_num)
-            + " and as endogenized exogenous " + symbol_table.getName(SymbolType::exogenous, it.var_num)
-            + " that do not appear in block=" + to_string(block_num+1)
-            + ")\nYou should not use block in model options"};
+        throw FatalException {"\nThe conditional forecast involving as constrained variable "
+                              + symbol_table.getName(SymbolType::endogenous, it.exo_num)
+                              + " and as endogenized exogenous "
+                              + symbol_table.getName(SymbolType::exogenous, it.var_num)
+                              + " that do not appear in block=" + to_string(block_num + 1)
+                              + ")\nYou should not use block in model options"};
       else if (find(endogenous.begin(), endogenous.end(), it.exo_num) != endogenous.end()
                && find(exogenous.begin(), exogenous.end(), it.var_num) != exogenous.end()
                && (type == BlockSimulationType::evaluateForward
                    || type == BlockSimulationType::evaluateBackward))
-        throw FatalException{"\nThe conditional forecast cannot be implemented for the block="
-            + to_string(block_num+1) + ") that has to be evaluated instead to be solved\nYou should not use block in model options"};
+        throw FatalException {"\nThe conditional forecast cannot be implemented for the block="
+                              + to_string(block_num + 1)
+                              + ") that has to be evaluated instead to be solved\nYou should not "
+                                "use block in model options"};
       else if (find(previous_block_exogenous.begin(), previous_block_exogenous.end(), it.var_num)
                != previous_block_exogenous.end())
-        throw FatalException{"\nThe conditional forecast involves in the block "
-            + to_string(block_num+1) + " the endogenized exogenous "
+        throw FatalException {
+            "\nThe conditional forecast involves in the block " + to_string(block_num + 1)
+            + " the endogenized exogenous "
             + symbol_table.getName(SymbolType::exogenous, it.var_num)
             + " that appear also in a previous block\nYou should not use block in model options"};
     }
@@ -681,14 +700,17 @@ Interpreter::check_for_controlled_exo_validity(const vector<s_plan> &sconstraine
 }
 
 pair<bool, vector<int>>
-Interpreter::MainLoop(const string &bin_basename, bool evaluate, int block, bool constrained, const vector<s_plan> &sconstrained_extended_path, const vector_table_conditional_local_type &vector_table_conditional_local)
+Interpreter::MainLoop(const string& bin_basename, bool evaluate, int block, bool constrained,
+                      const vector<s_plan>& sconstrained_extended_path,
+                      const vector_table_conditional_local_type& vector_table_conditional_local)
 {
   int nb_blocks {evaluator.getTotalBlockNumber()};
 
   if (block >= nb_blocks)
-    throw FatalException {"Interpreter::MainLoop: Input argument block = " + to_string(block+1)
-        + " is greater than the number of blocks in the model ("
-        + to_string(nb_blocks) + " see M_.block_structure" + (steady_state ? "_stat" : "") + ".block)"};
+    throw FatalException {"Interpreter::MainLoop: Input argument block = " + to_string(block + 1)
+                          + " is greater than the number of blocks in the model ("
+                          + to_string(nb_blocks) + " see M_.block_structure"
+                          + (steady_state ? "_stat" : "") + ".block)"};
 
   vector<int> blocks;
   if (block < 0)
@@ -711,7 +733,7 @@ Interpreter::MainLoop(const string &bin_basename, bool evaluate, int block, bool
       if (steady_state)
         residual = vector<double>(y_size);
       else
-        residual = vector<double>(y_size*periods);
+        residual = vector<double>(y_size * periods);
     }
 
   for (int current_block : blocks)
@@ -731,47 +753,57 @@ Interpreter::MainLoop(const string &bin_basename, bool evaluate, int block, bool
           if (steady_state)
             residual = vector<double>(size);
           else
-            residual = vector<double>(size*periods);
+            residual = vector<double>(size * periods);
           evaluator.printCurrentBlock();
         }
       else if (evaluate)
         {
 #ifdef DEBUG
-          mexPrintf("jacobian_block=mxCreateDoubleMatrix(%d, %d, mxREAL)\n", size, getCurrentBlockNbColJacob());
+          mexPrintf("jacobian_block=mxCreateDoubleMatrix(%d, %d, mxREAL)\n", size,
+                    getCurrentBlockNbColJacob());
 #endif
-          jacobian_block[current_block] = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockNbColJacob(), mxREAL);
+          jacobian_block[current_block]
+              = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockNbColJacob(), mxREAL);
           if (!steady_state)
             {
 #ifdef DEBUG
-              mexPrintf("allocates jacobian_exo_block( %d, %d, mxREAL)\n", size, evaluator.getCurrentBlockExoSize());
+              mexPrintf("allocates jacobian_exo_block( %d, %d, mxREAL)\n", size,
+                        evaluator.getCurrentBlockExoSize());
               mexPrintf("(0) Allocating Jacobian\n");
 #endif
 
-              jacobian_exo_block[current_block] = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockExoSize(), mxREAL);
-              jacobian_det_exo_block[current_block] = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockExoDetSize(), mxREAL);
+              jacobian_exo_block[current_block]
+                  = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockExoSize(), mxREAL);
+              jacobian_det_exo_block[current_block]
+                  = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockExoDetSize(), mxREAL);
             }
           if (block >= 0)
             {
               if (steady_state)
                 residual = vector<double>(size);
               else
-                residual = vector<double>(size*periods);
+                residual = vector<double>(size * periods);
             }
           evaluate_a_block(true, block >= 0, bin_basename);
         }
       else
         {
 #ifdef DEBUG
-          mexPrintf("endo in block %d, size=%d, type=%d, steady_state=%d, is_linear=%d, endo_nbr=%d, u_count_int=%d\n",
-                    current_block+1, size, type, steady_state, is_linear, symbol_table_endo_nbr, u_count_int);
+          mexPrintf("endo in block %d, size=%d, type=%d, steady_state=%d, is_linear=%d, "
+                    "endo_nbr=%d, u_count_int=%d\n",
+                    current_block + 1, size, type, steady_state, is_linear, symbol_table_endo_nbr,
+                    u_count_int);
 #endif
           bool result;
           if (sconstrained_extended_path.size())
             {
-              jacobian_block[current_block] = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockNbColJacob(), mxREAL);
-              jacobian_exo_block[current_block] = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockExoSize(), mxREAL);
-              jacobian_det_exo_block[current_block] = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockExoDetSize(), mxREAL);
-              residual = vector<double>(size*periods);
+              jacobian_block[current_block]
+                  = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockNbColJacob(), mxREAL);
+              jacobian_exo_block[current_block]
+                  = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockExoSize(), mxREAL);
+              jacobian_det_exo_block[current_block]
+                  = mxCreateDoubleMatrix(size, evaluator.getCurrentBlockExoDetSize(), mxREAL);
+              residual = vector<double>(size * periods);
               result = simulate_a_block(vector_table_conditional_local, block >= 0, bin_basename);
             }
           else
@@ -804,28 +836,28 @@ Interpreter::elastic(string str, unsigned int len, bool left)
         {
           if (left)
             {
-              //mexPrintf("(1) diff=%d\n",diff);
-              str.insert(str.end(), diff-1, ' ');
+              // mexPrintf("(1) diff=%d\n",diff);
+              str.insert(str.end(), diff - 1, ' ');
               str.insert(str.begin(), 1, ' ');
             }
           else
             {
-              str.insert(str.end(), diff/2, ' ');
-              str.insert(str.begin(), diff/2, ' ');
+              str.insert(str.end(), diff / 2, ' ');
+              str.insert(str.begin(), diff / 2, ' ');
             }
         }
       else
         {
           if (left)
             {
-              //mexPrintf("(2) diff=%d\n",diff);
-              str.insert(str.end(), diff-1, ' ');
+              // mexPrintf("(2) diff=%d\n",diff);
+              str.insert(str.end(), diff - 1, ' ');
               str.insert(str.begin(), 1, ' ');
             }
           else
             {
-              str.insert(str.end(), ceil(diff/2), ' ');
-              str.insert(str.begin(), ceil(diff/2+1), ' ');
+              str.insert(str.end(), ceil(diff / 2), ' ');
+              str.insert(str.begin(), ceil(diff / 2 + 1), ' ');
             }
         }
       return str;
@@ -833,19 +865,23 @@ Interpreter::elastic(string str, unsigned int len, bool left)
 }
 
 pair<bool, vector<int>>
-Interpreter::extended_path(const string &file_name, bool evaluate, int block, int nb_periods, const vector<s_plan> &sextended_path, const vector<s_plan> &sconstrained_extended_path, const vector<string> &dates, const table_conditional_global_type &table_conditional_global)
+Interpreter::extended_path(const string& file_name, bool evaluate, int block, int nb_periods,
+                           const vector<s_plan>& sextended_path,
+                           const vector<s_plan>& sconstrained_extended_path,
+                           const vector<string>& dates,
+                           const table_conditional_global_type& table_conditional_global)
 {
-  size_t size_of_direction = y_size*col_y*sizeof(double);
-  auto *y_save = static_cast<double *>(mxMalloc(size_of_direction));
+  size_t size_of_direction = y_size * col_y * sizeof(double);
+  auto* y_save = static_cast<double*>(mxMalloc(size_of_direction));
   test_mxMalloc(y_save, __LINE__, __FILE__, __func__, size_of_direction);
-  auto *x_save = static_cast<double *>(mxMalloc(nb_row_x * col_x *sizeof(double)));
-  test_mxMalloc(x_save, __LINE__, __FILE__, __func__, nb_row_x * col_x *sizeof(double));
+  auto* x_save = static_cast<double*>(mxMalloc(nb_row_x * col_x * sizeof(double)));
+  test_mxMalloc(x_save, __LINE__, __FILE__, __func__, nb_row_x * col_x * sizeof(double));
 
   vector_table_conditional_local_type vector_table_conditional_local;
   vector_table_conditional_local.clear();
 
   int endo_name_length_l = static_cast<int>(symbol_table.maxEndoNameLength());
-  for (int j = 0; j < col_x* nb_row_x; j++)
+  for (int j = 0; j < col_x * nb_row_x; j++)
     {
       x_save[j] = x[j];
       x[j] = 0;
@@ -862,7 +898,8 @@ Interpreter::extended_path(const string &file_name, bool evaluate, int block, in
   res1 << std::scientific << 2.54656875434865131;
   int real_max_length = res1.str().length();
   int date_length = dates[0].length();
-  int table_length = 2 + date_length + 3 + endo_name_length_l + 3 + real_max_length + 3 + 3 + 2 + 6 + 2;
+  int table_length
+      = 2 + date_length + 3 + endo_name_length_l + 3 + real_max_length + 3 + 3 + 2 + 6 + 2;
   string line;
   line.insert(line.begin(), table_length, '-');
   line.insert(line.length(), "\n");
@@ -871,7 +908,10 @@ Interpreter::extended_path(const string &file_name, bool evaluate, int block, in
       mexPrintf("\nExtended Path simulation:\n");
       mexPrintf("-------------------------\n");
       mexPrintf(line.c_str());
-      string title = "|" + elastic("date", date_length+2, false) + "|" + elastic("variable", endo_name_length_l+2, false) + "|" + elastic("max. value", real_max_length+2, false) + "| iter. |" + elastic("cvg", 5, false) + "|\n";
+      string title = "|" + elastic("date", date_length + 2, false) + "|"
+                     + elastic("variable", endo_name_length_l + 2, false) + "|"
+                     + elastic("max. value", real_max_length + 2, false) + "| iter. |"
+                     + elastic("cvg", 5, false) + "|\n";
       mexPrintf(title.c_str());
       mexPrintf(line.c_str());
     }
@@ -882,16 +922,17 @@ Interpreter::extended_path(const string &file_name, bool evaluate, int block, in
       previous_block_exogenous.clear();
       if (old_verbosity >= 1)
         {
-          mexPrintf("|%s|", elastic(dates[t], date_length+2, false).c_str());
+          mexPrintf("|%s|", elastic(dates[t], date_length + 2, false).c_str());
           mexEvalString("drawnow;");
         }
-      for (const auto & it : sextended_path)
+      for (const auto& it : sextended_path)
         x[y_kmin + (it.exo_num - 1) * nb_row_x] = it.value[t];
 
       vector_table_conditional_local.clear();
       if (auto it = table_conditional_global.find(t); it != table_conditional_global.end())
         vector_table_conditional_local = it->second;
-      tie(r, blocks) = MainLoop(file_name, evaluate, block, true, sconstrained_extended_path, vector_table_conditional_local);
+      tie(r, blocks) = MainLoop(file_name, evaluate, block, true, sconstrained_extended_path,
+                                vector_table_conditional_local);
       for (int j = 0; j < y_size; j++)
         {
           y_save[j + (t + y_kmin) * y_size] = y[j + y_kmin * y_size];
@@ -909,7 +950,11 @@ Interpreter::extended_path(const string &file_name, bool evaluate, int block, in
         {
           ostringstream res1;
           res1 << std::scientific << max_res;
-          mexPrintf("%s|%s| %4d  |  x  |\n", elastic(symbol_table.getName(SymbolType::endogenous, max_res_idx), endo_name_length_l+2, true).c_str(), elastic(res1.str(), real_max_length+2, false).c_str(), iter);
+          mexPrintf("%s|%s| %4d  |  x  |\n",
+                    elastic(symbol_table.getName(SymbolType::endogenous, max_res_idx),
+                            endo_name_length_l + 2, true)
+                        .c_str(),
+                    elastic(res1.str(), real_max_length + 2, false).c_str(), iter);
           mexPrintf(line.c_str());
           mexEvalString("drawnow;");
         }
@@ -928,13 +973,14 @@ Interpreter::extended_path(const string &file_name, bool evaluate, int block, in
 }
 
 pair<bool, vector<int>>
-Interpreter::compute_blocks(const string &file_name, bool evaluate, int block)
+Interpreter::compute_blocks(const string& file_name, bool evaluate, int block)
 {
-  //The big loop on intructions
+  // The big loop on intructions
   vector<s_plan> s_plan_junk;
   vector_table_conditional_local_type vector_table_conditional_local_junk;
 
-  auto [r, blocks] = MainLoop(file_name, evaluate, block, false, s_plan_junk, vector_table_conditional_local_junk);
+  auto [r, blocks] = MainLoop(file_name, evaluate, block, false, s_plan_junk,
+                              vector_table_conditional_local_junk);
 
   return {true, blocks};
 }
@@ -951,13 +997,13 @@ Interpreter::NCol(int c) const
   return NbNZCol[c];
 }
 
-pair<int, NonZeroElem *>
+pair<int, NonZeroElem*>
 Interpreter::At_Row(int r) const
 {
-  return { NbNZRow[r], FNZE_R[r] };
+  return {NbNZRow[r], FNZE_R[r]};
 }
 
-NonZeroElem *
+NonZeroElem*
 Interpreter::At_Pos(int r, int c) const
 {
   NonZeroElem* first {FNZE_R[r]};
@@ -966,22 +1012,22 @@ Interpreter::At_Pos(int r, int c) const
   return first;
 }
 
-pair<int, NonZeroElem *>
+pair<int, NonZeroElem*>
 Interpreter::At_Col(int c) const
 {
-  return { NbNZCol[c], FNZE_C[c] };
+  return {NbNZCol[c], FNZE_C[c]};
 }
 
-pair<int, NonZeroElem *>
+pair<int, NonZeroElem*>
 Interpreter::At_Col(int c, int lag) const
 {
-  NonZeroElem *first {FNZE_C[c]};
+  NonZeroElem* first {FNZE_C[c]};
   int i = 0;
   while (first->lag_index != lag && first)
     first = first->NZE_C_N;
   if (first)
     {
-      NonZeroElem *firsta {first};
+      NonZeroElem* firsta {first};
       if (!firsta->NZE_C_N)
         i++;
       else
@@ -995,7 +1041,7 @@ Interpreter::At_Col(int c, int lag) const
             i++;
         }
     }
-  return { i, first };
+  return {i, first};
 }
 
 void
@@ -1093,7 +1139,7 @@ Interpreter::Close_SaveCode()
 }
 
 void
-Interpreter::Read_SparseMatrix(const string &file_name, bool two_boundaries)
+Interpreter::Read_SparseMatrix(const string& file_name, bool two_boundaries)
 {
   unsigned int eq, var;
   int lag;
@@ -1101,45 +1147,44 @@ Interpreter::Read_SparseMatrix(const string &file_name, bool two_boundaries)
   if (!SaveCode.is_open())
     {
       filesystem::path binfile {file_name + "/model/bytecode/" + (block_decomposed ? "block/" : "")
-        + (steady_state ? "static" : "dynamic") + ".bin"};
+                                + (steady_state ? "static" : "dynamic") + ".bin"};
       SaveCode.open(binfile, ios::in | ios::binary);
       if (!SaveCode.is_open())
-        throw FatalException{"In Read_SparseMatrix, " + binfile.string() + " cannot be opened"};
+        throw FatalException {"In Read_SparseMatrix, " + binfile.string() + " cannot be opened"};
     }
   IM_i.clear();
   if (two_boundaries)
     {
       if (stack_solve_algo == 5)
         {
-          for (int i = 0; i < u_count_init-size; i++)
+          for (int i = 0; i < u_count_init - size; i++)
             {
               int val;
-              SaveCode.read(reinterpret_cast<char *>(&eq), sizeof(eq));
-              SaveCode.read(reinterpret_cast<char *>(&var), sizeof(var));
-              SaveCode.read(reinterpret_cast<char *>(&lag), sizeof(lag));
-              SaveCode.read(reinterpret_cast<char *>(&val), sizeof(val));
-              IM_i[{ eq, var, lag }] = val;
+              SaveCode.read(reinterpret_cast<char*>(&eq), sizeof(eq));
+              SaveCode.read(reinterpret_cast<char*>(&var), sizeof(var));
+              SaveCode.read(reinterpret_cast<char*>(&lag), sizeof(lag));
+              SaveCode.read(reinterpret_cast<char*>(&val), sizeof(val));
+              IM_i[{eq, var, lag}] = val;
             }
           for (int j = 0; j < size; j++)
-            IM_i[{ j, size*(periods+y_kmax), 0 }] = j;
+            IM_i[{j, size * (periods + y_kmax), 0}] = j;
         }
-      else if ((stack_solve_algo >= 0 && stack_solve_algo <= 4)
-               || stack_solve_algo == 6)
+      else if ((stack_solve_algo >= 0 && stack_solve_algo <= 4) || stack_solve_algo == 6)
         {
-          for (int i = 0; i < u_count_init-size; i++)
+          for (int i = 0; i < u_count_init - size; i++)
             {
               int val;
-              SaveCode.read(reinterpret_cast<char *>(&eq), sizeof(eq));
-              SaveCode.read(reinterpret_cast<char *>(&var), sizeof(var));
-              SaveCode.read(reinterpret_cast<char *>(&lag), sizeof(lag));
-              SaveCode.read(reinterpret_cast<char *>(&val), sizeof(val));
-              IM_i[{ var - lag*size, -lag, eq }] = val;
+              SaveCode.read(reinterpret_cast<char*>(&eq), sizeof(eq));
+              SaveCode.read(reinterpret_cast<char*>(&var), sizeof(var));
+              SaveCode.read(reinterpret_cast<char*>(&lag), sizeof(lag));
+              SaveCode.read(reinterpret_cast<char*>(&val), sizeof(val));
+              IM_i[{var - lag * size, -lag, eq}] = val;
             }
           for (int j = 0; j < size; j++)
-            IM_i[{ size*(periods+y_kmax), 0, j }] = j;
+            IM_i[{size * (periods + y_kmax), 0, j}] = j;
         }
       else
-        throw FatalException{"Invalid value for solve_algo or stack_solve_algo"};
+        throw FatalException {"Invalid value for solve_algo or stack_solve_algo"};
     }
   else
     {
@@ -1148,78 +1193,78 @@ Interpreter::Read_SparseMatrix(const string &file_name, bool two_boundaries)
           for (int i = 0; i < u_count_init; i++)
             {
               int val;
-              SaveCode.read(reinterpret_cast<char *>(&eq), sizeof(eq));
-              SaveCode.read(reinterpret_cast<char *>(&var), sizeof(var));
-              SaveCode.read(reinterpret_cast<char *>(&lag), sizeof(lag));
-              SaveCode.read(reinterpret_cast<char *>(&val), sizeof(val));
-              IM_i[{ eq, var, lag }] = val;
+              SaveCode.read(reinterpret_cast<char*>(&eq), sizeof(eq));
+              SaveCode.read(reinterpret_cast<char*>(&var), sizeof(var));
+              SaveCode.read(reinterpret_cast<char*>(&lag), sizeof(lag));
+              SaveCode.read(reinterpret_cast<char*>(&val), sizeof(val));
+              IM_i[{eq, var, lag}] = val;
             }
         }
-      else if ((((stack_solve_algo >= 0 && stack_solve_algo <= 4)
-                 || stack_solve_algo == 6) && !steady_state)
+      else if ((((stack_solve_algo >= 0 && stack_solve_algo <= 4) || stack_solve_algo == 6)
+                && !steady_state)
                || ((solve_algo >= 6 || solve_algo <= 8) && steady_state))
         {
           for (int i = 0; i < u_count_init; i++)
             {
               int val;
-              SaveCode.read(reinterpret_cast<char *>(&eq), sizeof(eq));
-              SaveCode.read(reinterpret_cast<char *>(&var), sizeof(var));
-              SaveCode.read(reinterpret_cast<char *>(&lag), sizeof(lag));
-              SaveCode.read(reinterpret_cast<char *>(&val), sizeof(val));
-              IM_i[{ var - lag*size, -lag, eq }] = val;
+              SaveCode.read(reinterpret_cast<char*>(&eq), sizeof(eq));
+              SaveCode.read(reinterpret_cast<char*>(&var), sizeof(var));
+              SaveCode.read(reinterpret_cast<char*>(&lag), sizeof(lag));
+              SaveCode.read(reinterpret_cast<char*>(&val), sizeof(val));
+              IM_i[{var - lag * size, -lag, eq}] = val;
             }
         }
       else
-        throw FatalException{"Invalid value for solve_algo or stack_solve_algo"};
+        throw FatalException {"Invalid value for solve_algo or stack_solve_algo"};
     }
 
-  int index_vara_size { size*(two_boundaries ? periods+y_kmin+y_kmax : 1) };
-  index_vara = static_cast<int *>(mxMalloc(index_vara_size*sizeof(int)));
-  test_mxMalloc(index_vara, __LINE__, __FILE__, __func__, index_vara_size*sizeof(int));
+  int index_vara_size {size * (two_boundaries ? periods + y_kmin + y_kmax : 1)};
+  index_vara = static_cast<int*>(mxMalloc(index_vara_size * sizeof(int)));
+  test_mxMalloc(index_vara, __LINE__, __FILE__, __func__, index_vara_size * sizeof(int));
   for (int j = 0; j < size; j++)
-    SaveCode.read(reinterpret_cast<char *>(&index_vara[j]), sizeof(*index_vara));
+    SaveCode.read(reinterpret_cast<char*>(&index_vara[j]), sizeof(*index_vara));
   if (two_boundaries)
-    for (int i = 1; i < periods+y_kmin+y_kmax; i++)
+    for (int i = 1; i < periods + y_kmin + y_kmax; i++)
       for (int j = 0; j < size; j++)
-        index_vara[j+size*i] = index_vara[j+size*(i-1)] + y_size;
-  index_equa = static_cast<int *>(mxMalloc(size*sizeof(int)));
-  test_mxMalloc(index_equa, __LINE__, __FILE__, __func__, size*sizeof(int));
+        index_vara[j + size * i] = index_vara[j + size * (i - 1)] + y_size;
+  index_equa = static_cast<int*>(mxMalloc(size * sizeof(int)));
+  test_mxMalloc(index_equa, __LINE__, __FILE__, __func__, size * sizeof(int));
   for (int j = 0; j < size; j++)
-    SaveCode.read(reinterpret_cast<char *>(&index_equa[j]), sizeof(*index_equa));
+    SaveCode.read(reinterpret_cast<char*>(&index_equa[j]), sizeof(*index_equa));
 }
 
 bool
 Interpreter::Simple_Init()
 {
-  pivot = static_cast<int *>(mxMalloc(size*sizeof(int)));
-  test_mxMalloc(pivot, __LINE__, __FILE__, __func__, size*sizeof(int));
-  pivot_save = static_cast<int *>(mxMalloc(size*sizeof(int)));
-  test_mxMalloc(pivot_save, __LINE__, __FILE__, __func__, size*sizeof(int));
-  pivotk = static_cast<int *>(mxMalloc(size*sizeof(int)));
-  test_mxMalloc(pivotk, __LINE__, __FILE__, __func__, size*sizeof(int));
-  pivotv = static_cast<double *>(mxMalloc(size*sizeof(double)));
-  test_mxMalloc(pivotv, __LINE__, __FILE__, __func__, size*sizeof(double));
-  pivotva = static_cast<double *>(mxMalloc(size*sizeof(double)));
-  test_mxMalloc(pivotva, __LINE__, __FILE__, __func__, size*sizeof(double));
-  b = static_cast<int *>(mxMalloc(size*sizeof(int)));
-  test_mxMalloc(b, __LINE__, __FILE__, __func__, size*sizeof(int));
-  line_done = static_cast<bool *>(mxMalloc(size*sizeof(bool)));
-  test_mxMalloc(line_done, __LINE__, __FILE__, __func__, size*sizeof(bool));
+  pivot = static_cast<int*>(mxMalloc(size * sizeof(int)));
+  test_mxMalloc(pivot, __LINE__, __FILE__, __func__, size * sizeof(int));
+  pivot_save = static_cast<int*>(mxMalloc(size * sizeof(int)));
+  test_mxMalloc(pivot_save, __LINE__, __FILE__, __func__, size * sizeof(int));
+  pivotk = static_cast<int*>(mxMalloc(size * sizeof(int)));
+  test_mxMalloc(pivotk, __LINE__, __FILE__, __func__, size * sizeof(int));
+  pivotv = static_cast<double*>(mxMalloc(size * sizeof(double)));
+  test_mxMalloc(pivotv, __LINE__, __FILE__, __func__, size * sizeof(double));
+  pivotva = static_cast<double*>(mxMalloc(size * sizeof(double)));
+  test_mxMalloc(pivotva, __LINE__, __FILE__, __func__, size * sizeof(double));
+  b = static_cast<int*>(mxMalloc(size * sizeof(int)));
+  test_mxMalloc(b, __LINE__, __FILE__, __func__, size * sizeof(int));
+  line_done = static_cast<bool*>(mxMalloc(size * sizeof(bool)));
+  test_mxMalloc(line_done, __LINE__, __FILE__, __func__, size * sizeof(bool));
 
   mem_mngr.init_CHUNK_BLCK_SIZE(u_count);
-  int i = size*sizeof(NonZeroElem *);
-  FNZE_R = static_cast<NonZeroElem **>(mxMalloc(i));
+  int i = size * sizeof(NonZeroElem*);
+  FNZE_R = static_cast<NonZeroElem**>(mxMalloc(i));
   test_mxMalloc(FNZE_R, __LINE__, __FILE__, __func__, i);
-  FNZE_C = static_cast<NonZeroElem **>(mxMalloc(i));
+  FNZE_C = static_cast<NonZeroElem**>(mxMalloc(i));
   test_mxMalloc(FNZE_C, __LINE__, __FILE__, __func__, i);
-  auto **temp_NZE_R = static_cast<NonZeroElem **>(mxMalloc(i));
+  auto** temp_NZE_R = static_cast<NonZeroElem**>(mxMalloc(i));
   test_mxMalloc(temp_NZE_R, __LINE__, __FILE__, __func__, i);
-  auto **temp_NZE_C = static_cast<NonZeroElem **>(mxMalloc(i));
+  auto** temp_NZE_C = static_cast<NonZeroElem**>(mxMalloc(i));
   test_mxMalloc(temp_NZE_C, __LINE__, __FILE__, __func__, i);
-  i = size*sizeof(int);
-  NbNZRow = static_cast<int *>(mxMalloc(i));
+  i = size * sizeof(int);
+  NbNZRow = static_cast<int*>(mxMalloc(i));
   test_mxMalloc(NbNZRow, __LINE__, __FILE__, __func__, i);
-  NbNZCol = static_cast<int *>(mxMalloc(i));
+  NbNZCol = static_cast<int*>(mxMalloc(i));
   test_mxMalloc(NbNZCol, __LINE__, __FILE__, __func__, i);
   for (i = 0; i < size; i++)
     {
@@ -1232,14 +1277,14 @@ Interpreter::Simple_Init()
       NbNZCol[i] = 0;
     }
   int u_count1 = size;
-  for (auto &[key, value] : IM_i)
+  for (auto& [key, value] : IM_i)
     {
-      auto &[eq, var, lag] = key;
+      auto& [eq, var, lag] = key;
       if (lag == 0) /*Build the index for sparse matrix containing the jacobian : u*/
         {
           NbNZRow[eq]++;
           NbNZCol[var]++;
-          NonZeroElem *first = mem_mngr.mxMalloc_NZE();
+          NonZeroElem* first = mem_mngr.mxMalloc_NZE();
           first->NZE_C_N = nullptr;
           first->NZE_R_N = nullptr;
           first->u_index = u_count1;
@@ -1265,7 +1310,7 @@ Interpreter::Simple_Init()
       b[i] = i;
       cum_abs_sum += fabs(u[i]);
     }
-  bool zero_solution { cum_abs_sum < 1e-20 };
+  bool zero_solution {cum_abs_sum < 1e-20};
 
   mxFree(temp_NZE_R);
   mxFree(temp_NZE_C);
@@ -1275,25 +1320,26 @@ Interpreter::Simple_Init()
 }
 
 bool
-Interpreter::Init_Matlab_Sparse_One_Boundary(const mxArray *A_m, const mxArray *b_m, const mxArray *x0_m) const
+Interpreter::Init_Matlab_Sparse_One_Boundary(const mxArray* A_m, const mxArray* b_m,
+                                             const mxArray* x0_m) const
 {
-  double *b = mxGetPr(b_m);
+  double* b = mxGetPr(b_m);
   if (!b)
-    throw FatalException{"In Init_Matlab_Sparse_One_Boundary, can't retrieve b vector"};
-  double *x0 = mxGetPr(x0_m);
+    throw FatalException {"In Init_Matlab_Sparse_One_Boundary, can't retrieve b vector"};
+  double* x0 = mxGetPr(x0_m);
   if (!x0)
-    throw FatalException{"In Init_Matlab_Sparse_One_Boundary, can't retrieve x0 vector"};
-  mwIndex *Ai = mxGetIr(A_m);
+    throw FatalException {"In Init_Matlab_Sparse_One_Boundary, can't retrieve x0 vector"};
+  mwIndex* Ai = mxGetIr(A_m);
   if (!Ai)
-    throw FatalException{"In Init_Matlab_Sparse_One_Boundary, can't allocate Ai index vector"};
-  mwIndex *Aj = mxGetJc(A_m);
+    throw FatalException {"In Init_Matlab_Sparse_One_Boundary, can't allocate Ai index vector"};
+  mwIndex* Aj = mxGetJc(A_m);
   if (!Aj)
-    throw FatalException{"In Init_Matlab_Sparse_One_Boundary, can't allocate Aj index vector"};
-  double *A = mxGetPr(A_m);
+    throw FatalException {"In Init_Matlab_Sparse_One_Boundary, can't allocate Aj index vector"};
+  double* A = mxGetPr(A_m);
   if (!A)
-    throw FatalException{"In Init_Matlab_Sparse_One_Boundary, can't retrieve A matrix"};
+    throw FatalException {"In Init_Matlab_Sparse_One_Boundary, can't retrieve A matrix"};
 
-  for (int i = 0; i < y_size*(periods+y_kmin); i++)
+  for (int i = 0; i < y_size * (periods + y_kmin); i++)
     ya[i] = y[i];
 #ifdef DEBUG
   unsigned int max_nze = mxGetNzmax(A_m);
@@ -1311,38 +1357,37 @@ Interpreter::Init_Matlab_Sparse_One_Boundary(const mxArray *A_m, const mxArray *
 
   Aj[0] = 0;
   last_var = 0;
-  for (auto &[key, index] : IM_i)
+  for (auto& [key, index] : IM_i)
     {
-      auto &[var, ignore, eq] = key;
+      auto& [var, ignore, eq] = key;
       if (var != last_var)
         {
-          Aj[1+last_var] = NZE;
+          Aj[1 + last_var] = NZE;
           last_var = var;
         }
 #ifdef DEBUG
-      if (index < 0 || index >= u_count_alloc || index > size + size*size)
-        throw FatalException{"In Init_Matlab_Sparse_One_Boundary, index (" + to_string(index)
-                             + ") out of range for u vector max = "
-                             + to_string(size+size*size)
-                             + " allocated = " + to_string(u_count_alloc)};
+      if (index < 0 || index >= u_count_alloc || index > size + size * size)
+        throw FatalException {"In Init_Matlab_Sparse_One_Boundary, index (" + to_string(index)
+                              + ") out of range for u vector max = " + to_string(size + size * size)
+                              + " allocated = " + to_string(u_count_alloc)};
       if (NZE >= max_nze)
-        throw FatalException{"In Init_Matlab_Sparse_One_Boundary, exceeds the capacity of A_m sparse matrix"};
+        throw FatalException {
+            "In Init_Matlab_Sparse_One_Boundary, exceeds the capacity of A_m sparse matrix"};
 #endif
       A[NZE] = u[index];
       Ai[NZE] = eq;
       NZE++;
 #ifdef DEBUG
       if (eq < 0 || eq >= size)
-        throw FatalException{"In Init_Matlab_Sparse_One_Boundary, index (" + to_string(eq)
-                             + ") out of range for b vector"};
+        throw FatalException {"In Init_Matlab_Sparse_One_Boundary, index (" + to_string(eq)
+                              + ") out of range for b vector"};
       if (var < 0 || var >= size)
-        throw FatalException{"In Init_Matlab_Sparse_One_Boundary, index (" + to_string(var)
-                             + ") out of range for index_vara vector"};
+        throw FatalException {"In Init_Matlab_Sparse_One_Boundary, index (" + to_string(var)
+                              + ") out of range for index_vara vector"};
       if (index_vara[var] < 0 || index_vara[var] >= y_size)
-        throw FatalException{"In Init_Matlab_Sparse_One_Boundary, index ("
-                             + to_string(index_vara[var])
-                             + ") out of range for y vector max=" + to_string(y_size)
-                             +" (0)"};
+        throw FatalException {"In Init_Matlab_Sparse_One_Boundary, index ("
+                              + to_string(index_vara[var])
+                              + ") out of range for y vector max=" + to_string(y_size) + " (0)"};
 #endif
     }
   Aj[size] = NZE;
@@ -1350,36 +1395,38 @@ Interpreter::Init_Matlab_Sparse_One_Boundary(const mxArray *A_m, const mxArray *
   return zero_solution;
 }
 
-tuple<bool, SuiteSparse_long *, SuiteSparse_long *, double *, double *>
-Interpreter::Init_UMFPACK_Sparse_One_Boundary(const mxArray *x0_m) const
+tuple<bool, SuiteSparse_long*, SuiteSparse_long*, double*, double*>
+Interpreter::Init_UMFPACK_Sparse_One_Boundary(const mxArray* x0_m) const
 {
-  double *b = static_cast<double *>(mxMalloc(size * sizeof(double)));
+  double* b = static_cast<double*>(mxMalloc(size * sizeof(double)));
   test_mxMalloc(b, __LINE__, __FILE__, __func__, size * sizeof(double));
   if (!b)
-    throw FatalException{"In Init_UMFPACK_Sparse_One_Boundary, can't retrieve b vector"};
-  double *x0 = mxGetPr(x0_m);
+    throw FatalException {"In Init_UMFPACK_Sparse_One_Boundary, can't retrieve b vector"};
+  double* x0 = mxGetPr(x0_m);
   if (!x0)
-    throw FatalException{"In Init_UMFPACK_Sparse_One_Boundary, can't retrieve x0 vector"};
-  SuiteSparse_long *Ap = static_cast<SuiteSparse_long *>(mxMalloc((size+1) * sizeof(SuiteSparse_long)));
-  test_mxMalloc(Ap, __LINE__, __FILE__, __func__, (size+1) * sizeof(SuiteSparse_long));
+    throw FatalException {"In Init_UMFPACK_Sparse_One_Boundary, can't retrieve x0 vector"};
+  SuiteSparse_long* Ap
+      = static_cast<SuiteSparse_long*>(mxMalloc((size + 1) * sizeof(SuiteSparse_long)));
+  test_mxMalloc(Ap, __LINE__, __FILE__, __func__, (size + 1) * sizeof(SuiteSparse_long));
   if (!Ap)
-    throw FatalException{"In Init_UMFPACK_Sparse_One_Boundary, can't allocate Ap index vector"};
+    throw FatalException {"In Init_UMFPACK_Sparse_One_Boundary, can't allocate Ap index vector"};
   size_t prior_nz = IM_i.size();
-  SuiteSparse_long *Ai = static_cast<SuiteSparse_long *>(mxMalloc(prior_nz * sizeof(SuiteSparse_long)));
+  SuiteSparse_long* Ai
+      = static_cast<SuiteSparse_long*>(mxMalloc(prior_nz * sizeof(SuiteSparse_long)));
   test_mxMalloc(Ai, __LINE__, __FILE__, __func__, prior_nz * sizeof(SuiteSparse_long));
   if (!Ai)
-    throw FatalException{"In Init_UMFPACK_Sparse_One_Boundary, can't allocate Ai index vector"};
-  double *Ax = static_cast<double *>(mxMalloc(prior_nz * sizeof(double)));
+    throw FatalException {"In Init_UMFPACK_Sparse_One_Boundary, can't allocate Ai index vector"};
+  double* Ax = static_cast<double*>(mxMalloc(prior_nz * sizeof(double)));
   test_mxMalloc(Ax, __LINE__, __FILE__, __func__, prior_nz * sizeof(double));
   if (!Ax)
-    throw FatalException{"In Init_UMFPACK_Sparse_One_Boundary, can't retrieve Ax matrix"};
+    throw FatalException {"In Init_UMFPACK_Sparse_One_Boundary, can't retrieve Ax matrix"};
   for (int i = 0; i < size; i++)
     {
       int eq = index_vara[i];
-      ya[eq+it_*y_size] = y[eq+it_*y_size];
+      ya[eq + it_ * y_size] = y[eq + it_ * y_size];
     }
 #ifdef DEBUG
-  unsigned int max_nze = prior_nz; //mxGetNzmax(A_m);
+  unsigned int max_nze = prior_nz; // mxGetNzmax(A_m);
 #endif
   unsigned int NZE = 0;
   int last_var = 0;
@@ -1394,47 +1441,46 @@ Interpreter::Init_UMFPACK_Sparse_One_Boundary(const mxArray *x0_m) const
 
   Ap[0] = 0;
   last_var = 0;
-  for (auto &[key, index] : IM_i)
+  for (auto& [key, index] : IM_i)
     {
-      auto &[var, ignore, eq] = key;
+      auto& [var, ignore, eq] = key;
       if (var != last_var)
         {
-          Ap[1+last_var] = NZE;
+          Ap[1 + last_var] = NZE;
           last_var = var;
         }
 #ifdef DEBUG
-      if (index < 0 || index >= u_count_alloc || index > size + size*size)
-        throw FatalException{"In Init_UMFPACK_Sparse_One_Boundary, index (" + to_string(index)
-                             + ") out of range for u vector max = "
-                             + to_string(size+size*size)
-                             + " allocated = " + to_string(u_count_alloc)};
+      if (index < 0 || index >= u_count_alloc || index > size + size * size)
+        throw FatalException {"In Init_UMFPACK_Sparse_One_Boundary, index (" + to_string(index)
+                              + ") out of range for u vector max = " + to_string(size + size * size)
+                              + " allocated = " + to_string(u_count_alloc)};
       if (NZE >= max_nze)
-        throw FatalException{"In Init_UMFPACK_Sparse_One_Boundary, exceeds the capacity of A_m sparse matrix"};
+        throw FatalException {
+            "In Init_UMFPACK_Sparse_One_Boundary, exceeds the capacity of A_m sparse matrix"};
 #endif
       Ax[NZE] = u[index];
       Ai[NZE] = eq;
       NZE++;
 #ifdef DEBUG
       if (eq < 0 || eq >= size)
-        throw FatalException{"In Init_UMFPACK_Sparse_One_Boundary, index (" + to_string(eq)
-                             + ") out of range for b vector"};
+        throw FatalException {"In Init_UMFPACK_Sparse_One_Boundary, index (" + to_string(eq)
+                              + ") out of range for b vector"};
       if (var < 0 || var >= size)
-        throw FatalException{"In Init_UMFPACK_Sparse_One_Boundary, index (" + to_string(var)
-                             + ") out of range for index_vara vector"};
+        throw FatalException {"In Init_UMFPACK_Sparse_One_Boundary, index (" + to_string(var)
+                              + ") out of range for index_vara vector"};
       if (index_vara[var] < 0 || index_vara[var] >= y_size)
-        throw FatalException{"In Init_UMFPACK_Sparse_One_Boundary, index ("
-                             + to_string(index_vara[var])
-                             + ") out of range for y vector max=" + to_string(y_size)
-                             + " (0)"};
+        throw FatalException {"In Init_UMFPACK_Sparse_One_Boundary, index ("
+                              + to_string(index_vara[var])
+                              + ") out of range for y vector max=" + to_string(y_size) + " (0)"};
 #endif
     }
   Ap[size] = NZE;
 
-  return { zero_solution, Ap, Ai, Ax, b };
+  return {zero_solution, Ap, Ai, Ax, b};
 }
 
 int
-Interpreter::find_exo_num(const vector<s_plan> &sconstrained_extended_path, int value)
+Interpreter::find_exo_num(const vector<s_plan>& sconstrained_extended_path, int value)
 {
   auto it = find_if(sconstrained_extended_path.begin(), sconstrained_extended_path.end(),
                     [=](auto v) { return v.exo_num == value; });
@@ -1445,7 +1491,7 @@ Interpreter::find_exo_num(const vector<s_plan> &sconstrained_extended_path, int
 }
 
 int
-Interpreter::find_int_date(const vector<pair<int, double>> &per_value, int value)
+Interpreter::find_int_date(const vector<pair<int, double>>& per_value, int value)
 {
   auto it = find_if(per_value.begin(), per_value.end(), [=](auto v) { return v.first == value; });
   if (it != per_value.end())
@@ -1454,39 +1500,43 @@ Interpreter::find_int_date(const vector<pair<int, double>> &per_value, int value
     return -1;
 }
 
-tuple<SuiteSparse_long *, SuiteSparse_long *, double *, double *>
-Interpreter::Init_UMFPACK_Sparse_Two_Boundaries(const mxArray *x0_m, const vector_table_conditional_local_type &vector_table_conditional_local) const
+tuple<SuiteSparse_long*, SuiteSparse_long*, double*, double*>
+Interpreter::Init_UMFPACK_Sparse_Two_Boundaries(
+    const mxArray* x0_m,
+    const vector_table_conditional_local_type& vector_table_conditional_local) const
 {
   int n = periods * size;
-  double *b = static_cast<double *>(mxMalloc(n * sizeof(double)));
+  double* b = static_cast<double*>(mxMalloc(n * sizeof(double)));
   if (!b)
-    throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, can't retrieve b vector"};
-  double *x0 = mxGetPr(x0_m);
+    throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, can't retrieve b vector"};
+  double* x0 = mxGetPr(x0_m);
   if (!x0)
-    throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, can't retrieve x0 vector"};
-  SuiteSparse_long *Ap = static_cast<SuiteSparse_long *>(mxMalloc((n+1) * sizeof(SuiteSparse_long)));
-  test_mxMalloc(Ap, __LINE__, __FILE__, __func__, (n+1) * sizeof(SuiteSparse_long));
+    throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, can't retrieve x0 vector"};
+  SuiteSparse_long* Ap
+      = static_cast<SuiteSparse_long*>(mxMalloc((n + 1) * sizeof(SuiteSparse_long)));
+  test_mxMalloc(Ap, __LINE__, __FILE__, __func__, (n + 1) * sizeof(SuiteSparse_long));
   if (!Ap)
-    throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, can't allocate Ap index vector"};
+    throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, can't allocate Ap index vector"};
   size_t prior_nz = IM_i.size() * periods;
-  SuiteSparse_long *Ai = static_cast<SuiteSparse_long *>(mxMalloc(prior_nz * sizeof(SuiteSparse_long)));
+  SuiteSparse_long* Ai
+      = static_cast<SuiteSparse_long*>(mxMalloc(prior_nz * sizeof(SuiteSparse_long)));
   test_mxMalloc(Ai, __LINE__, __FILE__, __func__, prior_nz * sizeof(SuiteSparse_long));
   if (!Ai)
-    throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, can't allocate Ai index vector"};
-  double *Ax = static_cast<double *>(mxMalloc(prior_nz * sizeof(double)));
+    throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, can't allocate Ai index vector"};
+  double* Ax = static_cast<double*>(mxMalloc(prior_nz * sizeof(double)));
   test_mxMalloc(Ax, __LINE__, __FILE__, __func__, prior_nz * sizeof(double));
   if (!Ax)
-    throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, can't retrieve Ax matrix"};
-  for (int i = 0; i < y_size*(periods+y_kmin); i++)
+    throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, can't retrieve Ax matrix"};
+  for (int i = 0; i < y_size * (periods + y_kmin); i++)
     ya[i] = y[i];
   unsigned int NZE = 0;
   int last_var = 0;
-  for (int i = 0; i < periods*size; i++)
+  for (int i = 0; i < periods * size; i++)
     {
       b[i] = 0;
-      x0[i] = y[index_vara[size*y_kmin+i]];
+      x0[i] = y[index_vara[size * y_kmin + i]];
     }
-  double *jacob_exo;
+  double* jacob_exo;
   int row_x = 0;
 #ifdef DEBUG
   int col_x;
@@ -1513,17 +1563,17 @@ Interpreter::Init_UMFPACK_Sparse_Two_Boundaries(const mxArray *x0_m, const vecto
     {
       last_var = -1;
       int var = 0;
-      for (auto &[key, value] : IM_i)
+      for (auto& [key, value] : IM_i)
         {
           var = get<0>(key);
-          int eq = get<2>(key)+size*t;
+          int eq = get<2>(key) + size * t;
           int lag = -get<1>(key);
-          int index = value + (t-lag) * u_count_init;
+          int index = value + (t - lag) * u_count_init;
           if (var != last_var)
             {
-              Ap[1+last_var + t * size] = NZE;
+              Ap[1 + last_var + t * size] = NZE;
               last_var = var;
-              if (var < size*(periods+y_kmax))
+              if (var < size * (periods + y_kmax))
                 {
                   if (t == 0 && vector_table_conditional_local.size())
                     {
@@ -1538,8 +1588,8 @@ Interpreter::Init_UMFPACK_Sparse_Two_Boundaries(const mxArray *x0_m, const vecto
             }
           if (fliped)
             {
-              if (t == 0 && var < (periods+y_kmax)*size
-                  && lag == 0 && vector_table_conditional_local.size())
+              if (t == 0 && var < (periods + y_kmax) * size && lag == 0
+                  && vector_table_conditional_local.size())
                 {
                   flip_exo = vector_table_conditional_local[var].var_exo;
 #ifdef DEBUG
@@ -1550,46 +1600,51 @@ Interpreter::Init_UMFPACK_Sparse_Two_Boundaries(const mxArray *x0_m, const vecto
                       fliped_exogenous_derivatives_updated = true;
                       for (int k = 0; k < row_x; k++)
                         {
-                          if (jacob_exo[k + row_x*flip_exo] != 0)
+                          if (jacob_exo[k + row_x * flip_exo] != 0)
                             {
-                              Ax[NZE] = jacob_exo[k + row_x*flip_exo];
+                              Ax[NZE] = jacob_exo[k + row_x * flip_exo];
                               Ai[NZE] = k;
                               NZE++;
 
 #ifdef DEBUG
                               if (local_index < 0 || local_index >= size * periods)
-                                throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
-                                                     + to_string(local_index)
-                                                     + ") out of range for b vector"};
-                              if (k + row_x*flip_exo < 0 || k + row_x*flip_exo >= row_x * col_x)
-                                throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
-                                                     + to_string(var+size*(y_kmin+t+lag))
-                                                     + ") out of range for jacob_exo vector"};
-                              if (t+y_kmin+flip_exo*nb_row_x < 0
-                                  || t+y_kmin+flip_exo*nb_row_x >= nb_row_x * this->col_x)
-                                throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
-                                                     + to_string(index_vara[var+size*(y_kmin+t+lag)])
-                                                     + ") out of range for x vector max="
-                                                     + to_string(nb_row_x * this->col_x)};
+                                throw FatalException {
+                                    "In Init_UMFPACK_Sparse_Two_Boundaries, index ("
+                                    + to_string(local_index) + ") out of range for b vector"};
+                              if (k + row_x * flip_exo < 0 || k + row_x * flip_exo >= row_x * col_x)
+                                throw FatalException {
+                                    "In Init_UMFPACK_Sparse_Two_Boundaries, index ("
+                                    + to_string(var + size * (y_kmin + t + lag))
+                                    + ") out of range for jacob_exo vector"};
+                              if (t + y_kmin + flip_exo * nb_row_x < 0
+                                  || t + y_kmin + flip_exo * nb_row_x >= nb_row_x * this->col_x)
+                                throw FatalException {
+                                    "In Init_UMFPACK_Sparse_Two_Boundaries, index ("
+                                    + to_string(index_vara[var + size * (y_kmin + t + lag)])
+                                    + ") out of range for x vector max="
+                                    + to_string(nb_row_x * this->col_x)};
 #endif
-                              u[k] -= jacob_exo[k + row_x*flip_exo] * x[t+y_kmin+flip_exo*nb_row_x];
+                              u[k] -= jacob_exo[k + row_x * flip_exo]
+                                      * x[t + y_kmin + flip_exo * nb_row_x];
                             }
                         }
                     }
                 }
             }
 
-          if (var < (periods+y_kmax)*size)
+          if (var < (periods + y_kmax) * size)
             {
               int ti_y_kmin = -min(t, y_kmin);
-              int ti_y_kmax = min(periods-(t+1), y_kmax);
+              int ti_y_kmax = min(periods - (t + 1), y_kmax);
               int ti_new_y_kmax = min(t, y_kmax);
-              int ti_new_y_kmin = -min(periods-(t+1), y_kmin);
-              if (lag <= ti_new_y_kmax && lag >= ti_new_y_kmin) /*Build the index for sparse matrix containing the jacobian : u*/
+              int ti_new_y_kmin = -min(periods - (t + 1), y_kmin);
+              if (lag <= ti_new_y_kmax && lag >= ti_new_y_kmin) /*Build the index for sparse matrix
+                                                                   containing the jacobian : u*/
                 {
 #ifdef DEBUG
                   if (NZE >= prior_nz)
-                    throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, exceeds the capacity of allocated sparse matrix"};
+                    throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, exceeds the "
+                                          "capacity of allocated sparse matrix"};
 #endif
                   if (!fliped)
                     {
@@ -1600,63 +1655,64 @@ Interpreter::Init_UMFPACK_Sparse_Two_Boundaries(const mxArray *x0_m, const vecto
                   else /*if (fliped)*/
                     {
 #ifdef DEBUG
-                      if (eq - lag * size < 0 || eq  - lag * size >= size * periods)
-                        throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
-                                             + to_string(eq  - lag * size)
-                                             + ") out of range for b vector"};
-                      if (var+size*(y_kmin+t) < 0
-                          || var+size*(y_kmin+t) >= size*(periods+y_kmin+y_kmax))
-                        throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
-                                             + to_string(var+size*(y_kmin+t))
-                                             + ") out of range for index_vara vector"};
-                      if (index_vara[var+size*(y_kmin+t)] < 0
-                          || index_vara[var+size*(y_kmin+t)] >= y_size*(periods+y_kmin+y_kmax))
-                        throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
-                                             + to_string(index_vara[var+size*(y_kmin+t)])
-                                             + ") out of range for y vector max="
-                                             + to_string(y_size*(periods+y_kmin+y_kmax))};
+                      if (eq - lag * size < 0 || eq - lag * size >= size * periods)
+                        throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
+                                              + to_string(eq - lag * size)
+                                              + ") out of range for b vector"};
+                      if (var + size * (y_kmin + t) < 0
+                          || var + size * (y_kmin + t) >= size * (periods + y_kmin + y_kmax))
+                        throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
+                                              + to_string(var + size * (y_kmin + t))
+                                              + ") out of range for index_vara vector"};
+                      if (index_vara[var + size * (y_kmin + t)] < 0
+                          || index_vara[var + size * (y_kmin + t)]
+                                 >= y_size * (periods + y_kmin + y_kmax))
+                        throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
+                                              + to_string(index_vara[var + size * (y_kmin + t)])
+                                              + ") out of range for y vector max="
+                                              + to_string(y_size * (periods + y_kmin + y_kmax))};
 #endif
-                      b[eq - lag * size] += u[index] * y[index_vara[var+size*(y_kmin+t)]];
+                      b[eq - lag * size] += u[index] * y[index_vara[var + size * (y_kmin + t)]];
                     }
-
                 }
               if (lag > ti_y_kmax || lag < ti_y_kmin)
                 {
 #ifdef DEBUG
                   if (eq < 0 || eq >= size * periods)
-                    throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
-                                         + to_string(eq)
-                                         + ") out of range for b vector"};
-                  if (var+size*(y_kmin+t+lag) < 0
-                      || var+size*(y_kmin+t+lag) >= size*(periods+y_kmin+y_kmax))
-                    throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
-                                         + to_string(var+size*(y_kmin+t+lag))
-                                         + ") out of range for index_vara vector"};
-                  if (index_vara[var+size*(y_kmin+t+lag)] < 0
-                      || index_vara[var+size*(y_kmin+t+lag)] >= y_size*(periods+y_kmin+y_kmax))
-                    throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
-                                         + to_string(index_vara[var+size*(y_kmin+t+lag)])
-                                         + ") out of range for y vector max="
-                                         + to_string(y_size*(periods+y_kmin+y_kmax))};
+                    throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
+                                          + to_string(eq) + ") out of range for b vector"};
+                  if (var + size * (y_kmin + t + lag) < 0
+                      || var + size * (y_kmin + t + lag) >= size * (periods + y_kmin + y_kmax))
+                    throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
+                                          + to_string(var + size * (y_kmin + t + lag))
+                                          + ") out of range for index_vara vector"};
+                  if (index_vara[var + size * (y_kmin + t + lag)] < 0
+                      || index_vara[var + size * (y_kmin + t + lag)]
+                             >= y_size * (periods + y_kmin + y_kmax))
+                    throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
+                                          + to_string(index_vara[var + size * (y_kmin + t + lag)])
+                                          + ") out of range for y vector max="
+                                          + to_string(y_size * (periods + y_kmin + y_kmax))};
 #endif
-                  b[eq] += u[index+lag*u_count_init]*y[index_vara[var+size*(y_kmin+t+lag)]];
+                  b[eq] += u[index + lag * u_count_init]
+                           * y[index_vara[var + size * (y_kmin + t + lag)]];
                 }
             }
           else /* ...and store it in the u vector*/
             {
 #ifdef DEBUG
               if (index < 0 || index >= u_count_alloc)
-                throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, index (" + to_string(index)
-                                     + ") out of range for u vector"};
-              if (eq < 0 || eq >= (size*periods))
-                throw FatalException{"In Init_UMFPACK_Sparse_Two_Boundaries, index (" + to_string(eq)
-                                     + ") out of range for b vector"};
+                throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
+                                      + to_string(index) + ") out of range for u vector"};
+              if (eq < 0 || eq >= (size * periods))
+                throw FatalException {"In Init_UMFPACK_Sparse_Two_Boundaries, index ("
+                                      + to_string(eq) + ") out of range for b vector"};
 #endif
               b[eq] += u[index];
             }
         }
     }
-  Ap[size*periods] = NZE;
+  Ap[size * periods] = NZE;
 #ifdef DEBUG
   mexPrintf("Ax = [");
   for (int i = 0; i < static_cast<int>(NZE); i++)
@@ -1664,7 +1720,7 @@ Interpreter::Init_UMFPACK_Sparse_Two_Boundaries(const mxArray *x0_m, const vecto
   mexPrintf("]\n");
 
   mexPrintf("Ap = [");
-  for (int i = 0; i < n+1; i++)
+  for (int i = 0; i < n + 1; i++)
     mexPrintf("%d ", Ap[i]);
   mexPrintf("]\n");
 
@@ -1674,69 +1730,72 @@ Interpreter::Init_UMFPACK_Sparse_Two_Boundaries(const mxArray *x0_m, const vecto
   mexPrintf("]\n");
 #endif
 
-  return { Ap, Ai, Ax, b };
+  return {Ap, Ai, Ax, b};
 }
 
 void
-Interpreter::Init_Matlab_Sparse_Two_Boundaries(const mxArray *A_m, const mxArray *b_m, const mxArray *x0_m) const
+Interpreter::Init_Matlab_Sparse_Two_Boundaries(const mxArray* A_m, const mxArray* b_m,
+                                               const mxArray* x0_m) const
 {
-  double *b = mxGetPr(b_m);
+  double* b = mxGetPr(b_m);
 
   if (!b)
-    throw FatalException{"In Init_Matlab_Sparse_Two_Boundaries, can't retrieve b vector"};
-  double *x0 = mxGetPr(x0_m);
+    throw FatalException {"In Init_Matlab_Sparse_Two_Boundaries, can't retrieve b vector"};
+  double* x0 = mxGetPr(x0_m);
   if (!x0)
-    throw FatalException{"In Init_Matlab_Sparse_Two_Boundaries, can't retrieve x0 vector"};
-  mwIndex *Aj = mxGetJc(A_m);
+    throw FatalException {"In Init_Matlab_Sparse_Two_Boundaries, can't retrieve x0 vector"};
+  mwIndex* Aj = mxGetJc(A_m);
   if (!Aj)
-    throw FatalException{"In Init_Matlab_Sparse_Two_Boundaries, can't allocate Aj index vector"};
-  mwIndex *Ai = mxGetIr(A_m);
+    throw FatalException {"In Init_Matlab_Sparse_Two_Boundaries, can't allocate Aj index vector"};
+  mwIndex* Ai = mxGetIr(A_m);
   if (!Ai)
-    throw FatalException{"In Init_Matlab_Sparse_Two_Boundaries, can't allocate Ai index vector"};
-  double *A = mxGetPr(A_m);
+    throw FatalException {"In Init_Matlab_Sparse_Two_Boundaries, can't allocate Ai index vector"};
+  double* A = mxGetPr(A_m);
   if (!A)
-    throw FatalException{"In Init_Matlab_Sparse_Two_Boundaries, can't retrieve A matrix"};
+    throw FatalException {"In Init_Matlab_Sparse_Two_Boundaries, can't retrieve A matrix"};
 
-  for (int i = 0; i < y_size*(periods+y_kmin); i++)
+  for (int i = 0; i < y_size * (periods + y_kmin); i++)
     ya[i] = y[i];
   unsigned int NZE = 0;
   int last_var = 0;
-  for (int i = 0; i < periods*size; i++)
+  for (int i = 0; i < periods * size; i++)
     {
       b[i] = 0;
-      x0[i] = y[index_vara[size*y_kmin+i]];
+      x0[i] = y[index_vara[size * y_kmin + i]];
     }
   Aj[0] = 0;
   for (int t = 0; t < periods; t++)
     {
       last_var = 0;
-      for (auto &[key, value] : IM_i)
+      for (auto& [key, value] : IM_i)
         {
           int var = get<0>(key);
           if (var != last_var)
             {
-              Aj[1+last_var + t * size] = NZE;
+              Aj[1 + last_var + t * size] = NZE;
               last_var = var;
             }
-          int eq = get<2>(key)+size*t;
+          int eq = get<2>(key) + size * t;
           int lag = -get<1>(key);
-          int index = value + (t-lag)*u_count_init;
-          if (var < (periods+y_kmax)*size)
+          int index = value + (t - lag) * u_count_init;
+          if (var < (periods + y_kmax) * size)
             {
               int ti_y_kmin = -min(t, y_kmin);
-              int ti_y_kmax = min(periods-(t +1), y_kmax);
+              int ti_y_kmax = min(periods - (t + 1), y_kmax);
               int ti_new_y_kmax = min(t, y_kmax);
-              int ti_new_y_kmin = -min(periods-(t+1), y_kmin);
-              if (lag <= ti_new_y_kmax && lag >= ti_new_y_kmin) /*Build the index for sparse matrix containing the jacobian : u*/
+              int ti_new_y_kmin = -min(periods - (t + 1), y_kmin);
+              if (lag <= ti_new_y_kmax && lag >= ti_new_y_kmin) /*Build the index for sparse matrix
+                                                                   containing the jacobian : u*/
                 {
 #ifdef DEBUG
-                  if (index < 0 || index >= u_count_alloc || index > size + size*size)
-                    throw FatalException{"In Init_Matlab_Sparse_Two_Boundaries, index (" + to_string(index)
-                                         + ") out of range for u vector max = "
-                                         + to_string(size+size*size) + " allocated = "
-                                         + to_string(u_count_alloc)};
+                  if (index < 0 || index >= u_count_alloc || index > size + size * size)
+                    throw FatalException {"In Init_Matlab_Sparse_Two_Boundaries, index ("
+                                          + to_string(index) + ") out of range for u vector max = "
+                                          + to_string(size + size * size)
+                                          + " allocated = " + to_string(u_count_alloc)};
                   if (NZE >= prior_nz)
-                    throw FatalException{"In Init_Matlab_Sparse_Two_Boundaries, exceeds the capacity of allocated sparse matrix"};
+                    throw FatalException {"In Init_Matlab_Sparse_Two_Boundaries, exceeds the "
+                                          "capacity of allocated sparse matrix"};
 #endif
                   A[NZE] = u[index];
                   Ai[NZE] = eq - lag * size;
@@ -1746,80 +1805,82 @@ Interpreter::Init_Matlab_Sparse_Two_Boundaries(const mxArray *A_m, const mxArray
                 {
 #ifdef DEBUG
                   if (eq < 0 || eq >= size * periods)
-                    throw FatalException{"In Init_Matlab_Sparse_Two_Boundaries, index (" + to_string(eq)
-                                         + ") out of range for b vector"};
-                  if (var+size*(y_kmin+t+lag) < 0
-                      || var+size*(y_kmin+t+lag) >= size*(periods+y_kmin+y_kmax))
-                    throw FatalException{"In Init_Matlab_Sparse_Two_Boundaries, index ("
-                                         + to_string(var+size*(y_kmin+t+lag))
-                                         + ") out of range for index_vara vector"};
-                  if (index_vara[var+size*(y_kmin+t+lag)] < 0
-                      || index_vara[var+size*(y_kmin+t+lag)] >= y_size*(periods+y_kmin+y_kmax))
-                    throw FatalException{"In Init_Matlab_Sparse_Two_Boundaries, index ("
-                                         + to_string(index_vara[var+size*(y_kmin+t+lag)])
-                                         + ") out of range for y vector max="
-                                         + to_string(y_size*(periods+y_kmin+y_kmax))};
+                    throw FatalException {"In Init_Matlab_Sparse_Two_Boundaries, index ("
+                                          + to_string(eq) + ") out of range for b vector"};
+                  if (var + size * (y_kmin + t + lag) < 0
+                      || var + size * (y_kmin + t + lag) >= size * (periods + y_kmin + y_kmax))
+                    throw FatalException {"In Init_Matlab_Sparse_Two_Boundaries, index ("
+                                          + to_string(var + size * (y_kmin + t + lag))
+                                          + ") out of range for index_vara vector"};
+                  if (index_vara[var + size * (y_kmin + t + lag)] < 0
+                      || index_vara[var + size * (y_kmin + t + lag)]
+                             >= y_size * (periods + y_kmin + y_kmax))
+                    throw FatalException {"In Init_Matlab_Sparse_Two_Boundaries, index ("
+                                          + to_string(index_vara[var + size * (y_kmin + t + lag)])
+                                          + ") out of range for y vector max="
+                                          + to_string(y_size * (periods + y_kmin + y_kmax))};
 #endif
-                  b[eq] += u[index+lag*u_count_init]*y[index_vara[var+size*(y_kmin+t+lag)]];
+                  b[eq] += u[index + lag * u_count_init]
+                           * y[index_vara[var + size * (y_kmin + t + lag)]];
                 }
             }
           else /* ...and store it in the u vector*/
             {
 #ifdef DEBUG
               if (index < 0 || index >= u_count_alloc)
-                throw FatalException{"In Init_Matlab_Sparse_Two_Boundaries, index (" + to_string(index)
-                                     + ") out of range for u vector"};
-              if (eq < 0 || eq >= (size*periods))
-                throw FatalException{"In Init_Matlab_Sparse_Two_Boundaries, index (" + to_string(eq)
-                                     + ") out of range for b vector"};
+                throw FatalException {"In Init_Matlab_Sparse_Two_Boundaries, index ("
+                                      + to_string(index) + ") out of range for u vector"};
+              if (eq < 0 || eq >= (size * periods))
+                throw FatalException {"In Init_Matlab_Sparse_Two_Boundaries, index ("
+                                      + to_string(eq) + ") out of range for b vector"};
 #endif
               b[eq] += u[index];
             }
         }
     }
-  Aj[size*periods] = NZE;
+  Aj[size * periods] = NZE;
 }
 
 void
 Interpreter::Init_Gaussian_Elimination()
 {
   double tmp_b = 0.0;
-  pivot = static_cast<int *>(mxMalloc(size*periods*sizeof(int)));
-  test_mxMalloc(pivot, __LINE__, __FILE__, __func__, size*periods*sizeof(int));
-  pivot_save = static_cast<int *>(mxMalloc(size*periods*sizeof(int)));
-  test_mxMalloc(pivot_save, __LINE__, __FILE__, __func__, size*periods*sizeof(int));
-  pivotk = static_cast<int *>(mxMalloc(size*periods*sizeof(int)));
-  test_mxMalloc(pivotk, __LINE__, __FILE__, __func__, size*periods*sizeof(int));
-  pivotv = static_cast<double *>(mxMalloc(size*periods*sizeof(double)));
-  test_mxMalloc(pivotv, __LINE__, __FILE__, __func__, size*periods*sizeof(double));
-  pivotva = static_cast<double *>(mxMalloc(size*periods*sizeof(double)));
-  test_mxMalloc(pivotva, __LINE__, __FILE__, __func__, size*periods*sizeof(double));
-  b = static_cast<int *>(mxMalloc(size*periods*sizeof(int)));
-  test_mxMalloc(b, __LINE__, __FILE__, __func__, size*periods*sizeof(int));
-  line_done = static_cast<bool *>(mxMalloc(size*periods*sizeof(bool)));
-  test_mxMalloc(line_done, __LINE__, __FILE__, __func__, size*periods*sizeof(bool));
+  pivot = static_cast<int*>(mxMalloc(size * periods * sizeof(int)));
+  test_mxMalloc(pivot, __LINE__, __FILE__, __func__, size * periods * sizeof(int));
+  pivot_save = static_cast<int*>(mxMalloc(size * periods * sizeof(int)));
+  test_mxMalloc(pivot_save, __LINE__, __FILE__, __func__, size * periods * sizeof(int));
+  pivotk = static_cast<int*>(mxMalloc(size * periods * sizeof(int)));
+  test_mxMalloc(pivotk, __LINE__, __FILE__, __func__, size * periods * sizeof(int));
+  pivotv = static_cast<double*>(mxMalloc(size * periods * sizeof(double)));
+  test_mxMalloc(pivotv, __LINE__, __FILE__, __func__, size * periods * sizeof(double));
+  pivotva = static_cast<double*>(mxMalloc(size * periods * sizeof(double)));
+  test_mxMalloc(pivotva, __LINE__, __FILE__, __func__, size * periods * sizeof(double));
+  b = static_cast<int*>(mxMalloc(size * periods * sizeof(int)));
+  test_mxMalloc(b, __LINE__, __FILE__, __func__, size * periods * sizeof(int));
+  line_done = static_cast<bool*>(mxMalloc(size * periods * sizeof(bool)));
+  test_mxMalloc(line_done, __LINE__, __FILE__, __func__, size * periods * sizeof(bool));
   mem_mngr.init_CHUNK_BLCK_SIZE(u_count);
-  int i = (periods+y_kmax+1)*size*sizeof(NonZeroElem *);
-  FNZE_R = static_cast<NonZeroElem **>(mxMalloc(i));
+  int i = (periods + y_kmax + 1) * size * sizeof(NonZeroElem*);
+  FNZE_R = static_cast<NonZeroElem**>(mxMalloc(i));
   test_mxMalloc(FNZE_R, __LINE__, __FILE__, __func__, i);
-  FNZE_C = static_cast<NonZeroElem **>(mxMalloc(i));
+  FNZE_C = static_cast<NonZeroElem**>(mxMalloc(i));
   test_mxMalloc(FNZE_C, __LINE__, __FILE__, __func__, i);
-  auto **temp_NZE_R = static_cast<NonZeroElem **>(mxMalloc(i));
+  auto** temp_NZE_R = static_cast<NonZeroElem**>(mxMalloc(i));
   test_mxMalloc(temp_NZE_R, __LINE__, __FILE__, __func__, i);
-  auto **temp_NZE_C = static_cast<NonZeroElem **>(mxMalloc(i));
+  auto** temp_NZE_C = static_cast<NonZeroElem**>(mxMalloc(i));
   test_mxMalloc(temp_NZE_C, __LINE__, __FILE__, __func__, i);
-  i = (periods+y_kmax+1)*size*sizeof(int);
-  NbNZRow = static_cast<int *>(mxMalloc(i));
+  i = (periods + y_kmax + 1) * size * sizeof(int);
+  NbNZRow = static_cast<int*>(mxMalloc(i));
   test_mxMalloc(NbNZRow, __LINE__, __FILE__, __func__, i);
-  NbNZCol = static_cast<int *>(mxMalloc(i));
+  NbNZCol = static_cast<int*>(mxMalloc(i));
   test_mxMalloc(NbNZCol, __LINE__, __FILE__, __func__, i);
 
-  for (int i = 0; i < periods*size; i++)
+  for (int i = 0; i < periods * size; i++)
     {
       b[i] = 0;
       line_done[i] = false;
     }
-  for (int i = 0; i < (periods+y_kmax+1)*size; i++)
+  for (int i = 0; i < (periods + y_kmax + 1) * size; i++)
     {
       FNZE_C[i] = nullptr;
       FNZE_R[i] = nullptr;
@@ -1829,33 +1890,35 @@ Interpreter::Init_Gaussian_Elimination()
       NbNZCol[i] = 0;
     }
   int nnz = 0;
-  //pragma omp parallel for ordered private(it4, ti_y_kmin, ti_y_kmax, eq, var, lag) schedule(dynamic)
+  // pragma omp parallel for ordered private(it4, ti_y_kmin, ti_y_kmax, eq, var, lag)
+  // schedule(dynamic)
   for (int t = 0; t < periods; t++)
     {
       int ti_y_kmin = -min(t, y_kmin);
-      int ti_y_kmax = min(periods-(t+1), y_kmax);
+      int ti_y_kmax = min(periods - (t + 1), y_kmax);
       int eq = -1;
-      //pragma omp ordered
-      for (auto &[key, value] : IM_i)
+      // pragma omp ordered
+      for (auto& [key, value] : IM_i)
         {
           int var = get<1>(key);
-          if (eq != get<0>(key)+size*t)
+          if (eq != get<0>(key) + size * t)
             tmp_b = 0;
-          eq = get<0>(key)+size*t;
+          eq = get<0>(key) + size * t;
           int lag = get<2>(key);
-          if (var < (periods+y_kmax)*size)
+          if (var < (periods + y_kmax) * size)
             {
               lag = get<2>(key);
-              if (lag <= ti_y_kmax && lag >= ti_y_kmin) /*Build the index for sparse matrix containing the jacobian : u*/
+              if (lag <= ti_y_kmax && lag >= ti_y_kmin) /*Build the index for sparse matrix
+                                                           containing the jacobian : u*/
                 {
                   nnz++;
-                  var += size*t;
+                  var += size * t;
                   NbNZRow[eq]++;
                   NbNZCol[var]++;
-                  NonZeroElem *first = mem_mngr.mxMalloc_NZE();
+                  NonZeroElem* first = mem_mngr.mxMalloc_NZE();
                   first->NZE_C_N = nullptr;
                   first->NZE_R_N = nullptr;
-                  first->u_index = value+u_count_init*t;
+                  first->u_index = value + u_count_init * t;
                   first->r_index = eq;
                   first->c_index = var;
                   first->lag_index = lag;
@@ -1870,17 +1933,18 @@ Interpreter::Init_Gaussian_Elimination()
                   temp_NZE_R[eq] = first;
                   temp_NZE_C[var] = first;
                 }
-              else /*Build the additive terms ooutside the simulation periods related to the first lags and the last leads...*/
+              else /*Build the additive terms ooutside the simulation periods related to the first
+                      lags and the last leads...*/
                 {
                   if (lag < ti_y_kmin)
-                    tmp_b += u[value+u_count_init*t]*y[index_vara[var+size*(y_kmin+t)]];
+                    tmp_b += u[value + u_count_init * t] * y[index_vara[var + size * (y_kmin + t)]];
                   else
-                    tmp_b += u[value+u_count_init*t]*y[index_vara[var+size*(y_kmin+t)]];
+                    tmp_b += u[value + u_count_init * t] * y[index_vara[var + size * (y_kmin + t)]];
                 }
             }
           else /* ...and store it in the u vector*/
             {
-              b[eq] = value+u_count_init*t;
+              b[eq] = value + u_count_init * t;
               u[b[eq]] += tmp_b;
               tmp_b = 0;
             }
@@ -1909,11 +1973,11 @@ Interpreter::Get_u()
         }
       else
         {
-          u_count_alloc += 5*u_count_alloc_save;
-          u = static_cast<double *>(mxRealloc(u, u_count_alloc*sizeof(double)));
+          u_count_alloc += 5 * u_count_alloc_save;
+          u = static_cast<double*>(mxRealloc(u, u_count_alloc * sizeof(double)));
           if (!u)
-            throw FatalException{"In Get_u, memory exhausted (realloc("
-                                 + to_string(u_count_alloc*sizeof(double)) + "))"};
+            throw FatalException {"In Get_u, memory exhausted (realloc("
+                                  + to_string(u_count_alloc * sizeof(double)) + "))"};
           int i = u_count;
           u_count++;
           return i;
@@ -1951,43 +2015,42 @@ Interpreter::End_Gaussian_Elimination()
 }
 
 bool
-Interpreter::compare(int *save_op, int *save_opa, int *save_opaa, int beg_t, long nop4)
+Interpreter::compare(int* save_op, int* save_opa, int* save_opaa, int beg_t, long nop4)
 {
-  long nop = nop4/2;
+  long nop = nop4 / 2;
   double r = 0.0;
   bool OK = true;
-  int *diff1 = static_cast<int *>(mxMalloc(nop*sizeof(int)));
-  test_mxMalloc(diff1, __LINE__, __FILE__, __func__, nop*sizeof(int));
-  int *diff2 = static_cast<int *>(mxMalloc(nop*sizeof(int)));
-  test_mxMalloc(diff2, __LINE__, __FILE__, __func__, nop*sizeof(int));
+  int* diff1 = static_cast<int*>(mxMalloc(nop * sizeof(int)));
+  test_mxMalloc(diff1, __LINE__, __FILE__, __func__, nop * sizeof(int));
+  int* diff2 = static_cast<int*>(mxMalloc(nop * sizeof(int)));
+  test_mxMalloc(diff2, __LINE__, __FILE__, __func__, nop * sizeof(int));
   int max_save_ops_first = -1;
   long j = 0, i = 0;
   while (i < nop4 && OK)
     {
-      t_save_op_s *save_op_s = reinterpret_cast<t_save_op_s *>(&save_op[i]);
-      t_save_op_s *save_opa_s = reinterpret_cast<t_save_op_s *>(&save_opa[i]);
-      t_save_op_s *save_opaa_s = reinterpret_cast<t_save_op_s *>(&save_opaa[i]);
-      diff1[j] = save_op_s->first-save_opa_s->first;
-      max_save_ops_first = max(max_save_ops_first, save_op_s->first+diff1[j]*(periods-beg_t));
+      t_save_op_s* save_op_s = reinterpret_cast<t_save_op_s*>(&save_op[i]);
+      t_save_op_s* save_opa_s = reinterpret_cast<t_save_op_s*>(&save_opa[i]);
+      t_save_op_s* save_opaa_s = reinterpret_cast<t_save_op_s*>(&save_opaa[i]);
+      diff1[j] = save_op_s->first - save_opa_s->first;
+      max_save_ops_first = max(max_save_ops_first, save_op_s->first + diff1[j] * (periods - beg_t));
       switch (save_op_s->operat)
         {
         case IFLD:
         case IFDIV:
           OK = (save_op_s->operat == save_opa_s->operat && save_opa_s->operat == save_opaa_s->operat
-                && diff1[j] == (save_opa_s->first-save_opaa_s->first));
+                && diff1[j] == (save_opa_s->first - save_opaa_s->first));
           i += 2;
           break;
         case IFLESS:
         case IFSUB:
-          diff2[j] = save_op_s->second-save_opa_s->second;
+          diff2[j] = save_op_s->second - save_opa_s->second;
           OK = (save_op_s->operat == save_opa_s->operat && save_opa_s->operat == save_opaa_s->operat
-                && diff1[j] == (save_opa_s->first-save_opaa_s->first)
-                && diff2[j] == (save_opa_s->second-save_opaa_s->second));
+                && diff1[j] == (save_opa_s->first - save_opaa_s->first)
+                && diff2[j] == (save_opa_s->second - save_opaa_s->second));
           i += 3;
           break;
         default:
-          throw FatalException{"In compare, unknown operator = "
-                               + to_string(save_op_s->operat)};
+          throw FatalException {"In compare, unknown operator = " + to_string(save_op_s->operat)};
         }
       j++;
     }
@@ -1996,22 +2059,22 @@ Interpreter::compare(int *save_op, int *save_opa, int *save_opaa, int beg_t, lon
     {
       for (int i = beg_t; i < periods; i++)
         for (int j = 0; j < size; j++)
-          pivot[i*size+j] = pivot[(i-1)*size+j]+size;
+          pivot[i * size + j] = pivot[(i - 1) * size + j] + size;
       if (max_save_ops_first >= u_count_alloc)
         {
           u_count_alloc += max_save_ops_first;
-          u = static_cast<double *>(mxRealloc(u, u_count_alloc*sizeof(double)));
+          u = static_cast<double*>(mxRealloc(u, u_count_alloc * sizeof(double)));
           if (!u)
-            throw FatalException{"In compare, memory exhausted (realloc("
-                                 + to_string(u_count_alloc*sizeof(double)) + "))"};
+            throw FatalException {"In compare, memory exhausted (realloc("
+                                  + to_string(u_count_alloc * sizeof(double)) + "))"};
         }
-      for (int t = 1; t < periods-beg_t-y_kmax; t++)
+      for (int t = 1; t < periods - beg_t - y_kmax; t++)
         {
           int i = j = 0;
           while (i < nop4)
             {
-              auto *save_op_s = reinterpret_cast<t_save_op_s *>(&save_op[i]);
-              double *up = &u[save_op_s->first+t*diff1[j]];
+              auto* save_op_s = reinterpret_cast<t_save_op_s*>(&save_op[i]);
+              double* up = &u[save_op_s->first + t * diff1[j]];
               switch (save_op_s->operat)
                 {
                 case IFLD:
@@ -2023,29 +2086,30 @@ Interpreter::compare(int *save_op, int *save_opa, int *save_opaa, int beg_t, lon
                   i += 2;
                   break;
                 case IFSUB:
-                  *up -= u[save_op_s->second+t*diff2[j]]*r;;
+                  *up -= u[save_op_s->second + t * diff2[j]] * r;
+                  ;
                   i += 3;
                   break;
                 case IFLESS:
-                  *up = -u[save_op_s->second+t*diff2[j]]*r;
+                  *up = -u[save_op_s->second + t * diff2[j]] * r;
                   i += 3;
                   break;
                 }
               j++;
             }
         }
-      int t1 = max(1, periods-beg_t-y_kmax);
-      int periods_beg_t = periods-beg_t;
+      int t1 = max(1, periods - beg_t - y_kmax);
+      int periods_beg_t = periods - beg_t;
       for (int t = t1; t < periods_beg_t; t++)
         {
           int i = j = 0;
-          int gap = periods_beg_t-t;
+          int gap = periods_beg_t - t;
           while (i < nop4)
             {
-              if (auto *save_op_s = reinterpret_cast<t_save_op_s *>(&save_op[i]);
+              if (auto* save_op_s = reinterpret_cast<t_save_op_s*>(&save_op[i]);
                   save_op_s->lag < gap)
                 {
-                  double *up = &u[save_op_s->first+t*diff1[j]];
+                  double* up = &u[save_op_s->first + t * diff1[j]];
                   switch (save_op_s->operat)
                     {
                     case IFLD:
@@ -2057,11 +2121,11 @@ Interpreter::compare(int *save_op, int *save_opa, int *save_opaa, int beg_t, lon
                       i += 2;
                       break;
                     case IFSUB:
-                      *up -= u[save_op_s->second+t*diff2[j]]*r;
+                      *up -= u[save_op_s->second + t * diff2[j]] * r;
                       i += 3;
                       break;
                     case IFLESS:
-                      *up = -u[save_op_s->second+t*diff2[j]]*r;
+                      *up = -u[save_op_s->second + t * diff2[j]] * r;
                       i += 3;
                       break;
                     }
@@ -2092,120 +2156,120 @@ Interpreter::complete(int beg_t)
 {
   double yy = 0.0;
 
-  int size_of_save_code = (1+y_kmax)*size*(size+1+4)/2*4;
-  int *save_code = static_cast<int *>(mxMalloc(size_of_save_code*sizeof(int)));
-  test_mxMalloc(save_code, __LINE__, __FILE__, __func__, size_of_save_code*sizeof(int));
-  int size_of_diff = (1+y_kmax)*size*(size+1+4);
-  int *diff = static_cast<int *>(mxMalloc(size_of_diff*sizeof(int)));
-  test_mxMalloc(diff, __LINE__, __FILE__, __func__, size_of_diff*sizeof(int));
-  long cal_y = y_size*y_kmin;
+  int size_of_save_code = (1 + y_kmax) * size * (size + 1 + 4) / 2 * 4;
+  int* save_code = static_cast<int*>(mxMalloc(size_of_save_code * sizeof(int)));
+  test_mxMalloc(save_code, __LINE__, __FILE__, __func__, size_of_save_code * sizeof(int));
+  int size_of_diff = (1 + y_kmax) * size * (size + 1 + 4);
+  int* diff = static_cast<int*>(mxMalloc(size_of_diff * sizeof(int)));
+  test_mxMalloc(diff, __LINE__, __FILE__, __func__, size_of_diff * sizeof(int));
+  long cal_y = y_size * y_kmin;
 
-  long i = (beg_t+1)*size-1;
+  long i = (beg_t + 1) * size - 1;
   long nop = 0;
-  for (long j = i; j > i-size; j--)
+  for (long j = i; j > i - size; j--)
     {
       long pos = pivot[j];
-      NonZeroElem *first;
+      NonZeroElem* first;
       long nb_var;
       tie(nb_var, first) = At_Row(pos);
       first = first->NZE_R_N;
       nb_var--;
       save_code[nop] = IFLDZ;
-      save_code[nop+1] = 0;
-      save_code[nop+2] = 0;
-      save_code[nop+3] = 0;
+      save_code[nop + 1] = 0;
+      save_code[nop + 2] = 0;
+      save_code[nop + 3] = 0;
 #ifdef DEBUG
-      if ((nop+3) >= size_of_save_code)
-        mexPrintf("out of save_code[%d] (bound=%d)\n", nop+2, size_of_save_code);
+      if ((nop + 3) >= size_of_save_code)
+        mexPrintf("out of save_code[%d] (bound=%d)\n", nop + 2, size_of_save_code);
 #endif
       nop += 4;
       for (long k = 0; k < nb_var; k++)
         {
           save_code[nop] = IFMUL;
-          save_code[nop+1] = index_vara[first->c_index]+cal_y;
-          save_code[nop+2] = first->u_index;
-          save_code[nop+3] = first->lag_index;
+          save_code[nop + 1] = index_vara[first->c_index] + cal_y;
+          save_code[nop + 2] = first->u_index;
+          save_code[nop + 3] = first->lag_index;
 #ifdef DEBUG
-          if ((nop+3) >= size_of_save_code)
-            mexPrintf("out of save_code[%d] (bound=%d)\n", nop+2, size_of_save_code);
+          if ((nop + 3) >= size_of_save_code)
+            mexPrintf("out of save_code[%d] (bound=%d)\n", nop + 2, size_of_save_code);
 #endif
           nop += 4;
           first = first->NZE_R_N;
         }
       save_code[nop] = IFADD;
-      save_code[nop+1] = b[pos];
-      save_code[nop+2] = 0;
-      save_code[nop+3] = 0;
+      save_code[nop + 1] = b[pos];
+      save_code[nop + 2] = 0;
+      save_code[nop + 3] = 0;
 #ifdef DEBUG
-      if ((nop+3) >= size_of_save_code)
-        mexPrintf("out of save_code[%d] (bound=%d)\n", nop+2, size_of_save_code);
+      if ((nop + 3) >= size_of_save_code)
+        mexPrintf("out of save_code[%d] (bound=%d)\n", nop + 2, size_of_save_code);
 #endif
       nop += 4;
       save_code[nop] = IFSTP;
-      save_code[nop+1] = index_vara[j]+y_size*y_kmin;
-      save_code[nop+2] = 0;
-      save_code[nop+3] = 0;
+      save_code[nop + 1] = index_vara[j] + y_size * y_kmin;
+      save_code[nop + 2] = 0;
+      save_code[nop + 3] = 0;
 #ifdef DEBUG
-      if ((nop+2) >= size_of_save_code)
-        mexPrintf("out of save_code[%d] (bound=%d)\n", nop+2, size_of_save_code);
+      if ((nop + 2) >= size_of_save_code)
+        mexPrintf("out of save_code[%d] (bound=%d)\n", nop + 2, size_of_save_code);
 #endif
       nop += 4;
     }
-  i = beg_t*size-1;
+  i = beg_t * size - 1;
   long nop1 = 0, nopa = 0;
-  for (long j = i; j > i-size; j--)
+  for (long j = i; j > i - size; j--)
     {
       long pos = pivot[j];
-      NonZeroElem *first;
+      NonZeroElem* first;
       long nb_var;
       tie(nb_var, first) = At_Row(pos);
       first = first->NZE_R_N;
       nb_var--;
       diff[nopa] = 0;
-      diff[nopa+1] = 0;
+      diff[nopa + 1] = 0;
       nopa += 2;
       nop1 += 4;
       for (long k = 0; k < nb_var; k++)
         {
-          diff[nopa] = save_code[nop1+1]-(index_vara[first->c_index]+cal_y);
-          diff[nopa+1] = save_code[nop1+2]-(first->u_index);
+          diff[nopa] = save_code[nop1 + 1] - (index_vara[first->c_index] + cal_y);
+          diff[nopa + 1] = save_code[nop1 + 2] - (first->u_index);
 #ifdef DEBUG
-          if ((nop1+2) >= size_of_save_code)
-            mexPrintf("out of save_code[%d] (bound=%d)\n", nop1+2, size_of_save_code);
-          if ((nopa+1) >= size_of_diff)
-            mexPrintf("out of diff[%d] (bound=%d)\n", nopa+2, size_of_diff);
+          if ((nop1 + 2) >= size_of_save_code)
+            mexPrintf("out of save_code[%d] (bound=%d)\n", nop1 + 2, size_of_save_code);
+          if ((nopa + 1) >= size_of_diff)
+            mexPrintf("out of diff[%d] (bound=%d)\n", nopa + 2, size_of_diff);
 #endif
           nopa += 2;
           nop1 += 4;
           first = first->NZE_R_N;
         }
-      diff[nopa] = save_code[nop1+1]-(b[pos]);
-      diff[nopa+1] = 0;
+      diff[nopa] = save_code[nop1 + 1] - (b[pos]);
+      diff[nopa + 1] = 0;
 #ifdef DEBUG
-      if ((nop1+3) >= size_of_save_code)
-        mexPrintf("out of save_code[%d] (bound=%d)\n", nop1+2, size_of_save_code);
-      if ((nopa+1) >= size_of_diff)
-        mexPrintf("out of diff[%d] (bound=%d)\n", nopa+2, size_of_diff);
+      if ((nop1 + 3) >= size_of_save_code)
+        mexPrintf("out of save_code[%d] (bound=%d)\n", nop1 + 2, size_of_save_code);
+      if ((nopa + 1) >= size_of_diff)
+        mexPrintf("out of diff[%d] (bound=%d)\n", nopa + 2, size_of_diff);
 #endif
       nopa += 2;
       nop1 += 4;
-      diff[nopa] = save_code[nop1+1]-(index_vara[j]+y_size*y_kmin);
-      diff[nopa+1] = 0;
+      diff[nopa] = save_code[nop1 + 1] - (index_vara[j] + y_size * y_kmin);
+      diff[nopa + 1] = 0;
 #ifdef DEBUG
-      if ((nop1+4) >= size_of_save_code)
-        mexPrintf("out of save_code[%d] (bound=%d)\n", nop1+2, size_of_save_code);
-      if ((nopa+1) >= size_of_diff)
-        mexPrintf("out of diff[%d] (bound=%d)\n", nopa+2, size_of_diff);
+      if ((nop1 + 4) >= size_of_save_code)
+        mexPrintf("out of save_code[%d] (bound=%d)\n", nop1 + 2, size_of_save_code);
+      if ((nopa + 1) >= size_of_diff)
+        mexPrintf("out of diff[%d] (bound=%d)\n", nopa + 2, size_of_diff);
 #endif
       nopa += 2;
       nop1 += 4;
     }
-  long max_var = (periods+y_kmin)*y_size;
-  long min_var = y_kmin*y_size;
-  for (int t = periods+y_kmin-1; t >= beg_t+y_kmin; t--)
+  long max_var = (periods + y_kmin) * y_size;
+  long min_var = y_kmin * y_size;
+  for (int t = periods + y_kmin - 1; t >= beg_t + y_kmin; t--)
     {
       int j = 0, k;
-      int ti = t-y_kmin-beg_t;
+      int ti = t - y_kmin - beg_t;
       for (int i = 0; i < nop; i += 4)
         {
           switch (save_code[i])
@@ -2214,17 +2278,17 @@ Interpreter::complete(int beg_t)
               yy = 0;
               break;
             case IFMUL:
-              k = save_code[i+1]+ti*diff[j];
+              k = save_code[i + 1] + ti * diff[j];
               if (k < max_var && k > min_var)
-                yy += y[k]*u[save_code[i+2]+ti*diff[j+1]];
+                yy += y[k] * u[save_code[i + 2] + ti * diff[j + 1]];
               break;
             case IFADD:
-              yy = -(yy+u[save_code[i+1]+ti*diff[j]]);
+              yy = -(yy + u[save_code[i + 1] + ti * diff[j]]);
               break;
             case IFSTP:
-              k = save_code[i+1]+ti*diff[j];
+              k = save_code[i + 1] + ti * diff[j];
               double err = yy - y[k];
-              y[k] += slowc*(err);
+              y[k] += slowc * (err);
               break;
             }
           j += 2;
@@ -2238,34 +2302,34 @@ Interpreter::complete(int beg_t)
 void
 Interpreter::bksub(int tbreak, int last_period)
 {
-  for (int i = 0; i < y_size*(periods+y_kmin); i++)
+  for (int i = 0; i < y_size * (periods + y_kmin); i++)
     y[i] = ya[i];
   if (symbolic && tbreak)
     last_period = complete(tbreak);
   else
     last_period = periods;
-  for (int t = last_period+y_kmin-1; t >= y_kmin; t--)
+  for (int t = last_period + y_kmin - 1; t >= y_kmin; t--)
     {
-      int ti = (t-y_kmin)*size;
-      int cal = y_kmin*size;
-      int cal_y = y_size*y_kmin;
-      for (int i = ti-1; i >= ti-size; i--)
+      int ti = (t - y_kmin) * size;
+      int cal = y_kmin * size;
+      int cal_y = y_size * y_kmin;
+      for (int i = ti - 1; i >= ti - size; i--)
         {
-          int j = i+cal;
-          int pos = pivot[i+size];
+          int j = i + cal;
+          int pos = pivot[i + size];
           auto [nb_var, first] = At_Row(pos);
           first = first->NZE_R_N;
           nb_var--;
-          int eq = index_vara[j]+y_size;
+          int eq = index_vara[j] + y_size;
           double yy = 0;
           for (int k = 0; k < nb_var; k++)
             {
-              yy += y[index_vara[first->c_index]+cal_y]*u[first->u_index];
+              yy += y[index_vara[first->c_index] + cal_y] * u[first->u_index];
               first = first->NZE_R_N;
             }
-          yy = -(yy+y[eq]+u[b[pos]]);
+          yy = -(yy + y[eq] + u[b[pos]]);
           direction[eq] = yy;
-          y[eq] += slowc*yy;
+          y[eq] += slowc * yy;
         }
     }
 }
@@ -2274,8 +2338,8 @@ void
 Interpreter::simple_bksub()
 {
   for (int i = 0; i < y_size; i++)
-    y[i+it_*y_size] = ya[i+it_*y_size];
-  for (int i = size-1; i >= 0; i--)
+    y[i + it_ * y_size] = ya[i + it_ * y_size];
+  for (int i = size - 1; i >= 0; i--)
     {
       int pos = pivot[i];
       auto [nb_var, first] = At_Row(pos);
@@ -2285,61 +2349,61 @@ Interpreter::simple_bksub()
       double yy = 0;
       for (int k = 0; k < nb_var; k++)
         {
-          yy += y[index_vara[first->c_index]+it_*y_size]*u[first->u_index];
+          yy += y[index_vara[first->c_index] + it_ * y_size] * u[first->u_index];
           first = first->NZE_R_N;
         }
-      yy = -(yy+y[eq+it_*y_size]+u[b[pos]]);
-      direction[eq+it_*y_size] = yy;
-      y[eq+it_*y_size] += slowc*yy;
+      yy = -(yy + y[eq + it_ * y_size] + u[b[pos]]);
+      direction[eq + it_ * y_size] = yy;
+      y[eq + it_ * y_size] += slowc * yy;
     }
 }
 
-mxArray *
-Interpreter::subtract_A_B(const mxArray *A_m, const mxArray *B_m)
+mxArray*
+Interpreter::subtract_A_B(const mxArray* A_m, const mxArray* B_m)
 {
   size_t n_A = mxGetN(A_m);
   size_t m_A = mxGetM(A_m);
-  double *A_d = mxGetPr(A_m);
+  double* A_d = mxGetPr(A_m);
   size_t n_B = mxGetN(B_m);
-  double *B_d = mxGetPr(B_m);
-  mxArray *C_m = mxCreateDoubleMatrix(m_A, n_B, mxREAL);
-  double *C_d = mxGetPr(C_m);
+  double* B_d = mxGetPr(B_m);
+  mxArray* C_m = mxCreateDoubleMatrix(m_A, n_B, mxREAL);
+  double* C_d = mxGetPr(C_m);
   for (int j = 0; j < static_cast<int>(n_A); j++)
     for (unsigned int i = 0; i < m_A; i++)
       {
-        size_t index = j*m_A+i;
+        size_t index = j * m_A + i;
         C_d[index] = A_d[index] - B_d[index];
       }
   return C_m;
 }
 
-mxArray *
-Interpreter::Sparse_subtract_SA_SB(const mxArray *A_m, const mxArray *B_m)
+mxArray*
+Interpreter::Sparse_subtract_SA_SB(const mxArray* A_m, const mxArray* B_m)
 {
   size_t n_A = mxGetN(A_m);
   size_t m_A = mxGetM(A_m);
-  mwIndex *A_i = mxGetIr(A_m);
-  mwIndex *A_j = mxGetJc(A_m);
+  mwIndex* A_i = mxGetIr(A_m);
+  mwIndex* A_j = mxGetJc(A_m);
   size_t total_nze_A = A_j[n_A];
-  double *A_d = mxGetPr(A_m);
+  double* A_d = mxGetPr(A_m);
   size_t n_B = mxGetN(B_m);
-  mwIndex *B_i = mxGetIr(B_m);
-  mwIndex *B_j = mxGetJc(B_m);
+  mwIndex* B_i = mxGetIr(B_m);
+  mwIndex* B_j = mxGetJc(B_m);
   size_t total_nze_B = B_j[n_B];
-  double *B_d = mxGetPr(B_m);
-  mxArray *C_m = mxCreateSparse(m_A, n_B, m_A*n_B, mxREAL);
-  mwIndex *C_i = mxGetIr(C_m);
-  mwIndex *C_j = mxGetJc(C_m);
-  double *C_d = mxGetPr(C_m);
+  double* B_d = mxGetPr(B_m);
+  mxArray* C_m = mxCreateSparse(m_A, n_B, m_A * n_B, mxREAL);
+  mwIndex* C_i = mxGetIr(C_m);
+  mwIndex* C_j = mxGetJc(C_m);
+  double* C_d = mxGetPr(C_m);
   unsigned int nze_B = 0, nze_C = 0, nze_A = 0;
   unsigned int A_col = 0, B_col = 0, C_col = 0;
   C_j[C_col] = 0;
   while (nze_A < total_nze_A || nze_B < total_nze_B)
     {
-      while (nze_A >= static_cast<unsigned int>(A_j[A_col+1]) && (nze_A < total_nze_A))
+      while (nze_A >= static_cast<unsigned int>(A_j[A_col + 1]) && (nze_A < total_nze_A))
         A_col++;
       size_t A_row = A_i[nze_A];
-      while (nze_B >= static_cast<unsigned int>(B_j[B_col+1]) && (nze_B < total_nze_B))
+      while (nze_B >= static_cast<unsigned int>(B_j[B_col + 1]) && (nze_B < total_nze_B))
         B_col++;
       size_t B_row = B_i[nze_B];
       if (A_col == B_col)
@@ -2350,7 +2414,7 @@ Interpreter::Sparse_subtract_SA_SB(const mxArray *A_m, const mxArray *B_m)
               C_i[nze_C] = A_row;
               while (C_col < A_col)
                 C_j[++C_col] = nze_C;
-              C_j[A_col+1] = nze_C++;
+              C_j[A_col + 1] = nze_C++;
               C_col = A_col;
             }
           else if ((A_row < B_row && nze_A < total_nze_A) || nze_B == total_nze_B)
@@ -2359,7 +2423,7 @@ Interpreter::Sparse_subtract_SA_SB(const mxArray *A_m, const mxArray *B_m)
               C_i[nze_C] = A_row;
               while (C_col < A_col)
                 C_j[++C_col] = nze_C;
-              C_j[A_col+1] = nze_C++;
+              C_j[A_col + 1] = nze_C++;
               C_col = A_col;
             }
           else
@@ -2368,7 +2432,7 @@ Interpreter::Sparse_subtract_SA_SB(const mxArray *A_m, const mxArray *B_m)
               C_i[nze_C] = B_row;
               while (C_col < B_col)
                 C_j[++C_col] = nze_C;
-              C_j[B_col+1] = nze_C++;
+              C_j[B_col + 1] = nze_C++;
               C_col = B_col;
             }
         }
@@ -2378,7 +2442,7 @@ Interpreter::Sparse_subtract_SA_SB(const mxArray *A_m, const mxArray *B_m)
           C_i[nze_C] = A_row;
           while (C_col < A_col)
             C_j[++C_col] = nze_C;
-          C_j[A_col+1] = nze_C++;
+          C_j[A_col + 1] = nze_C++;
           C_col = A_col;
         }
       else
@@ -2387,7 +2451,7 @@ Interpreter::Sparse_subtract_SA_SB(const mxArray *A_m, const mxArray *B_m)
           C_i[nze_C] = B_row;
           while (C_col < B_col)
             C_j[++C_col] = nze_C;
-          C_j[B_col+1] = nze_C++;
+          C_j[B_col + 1] = nze_C++;
           C_col = B_col;
         }
     }
@@ -2397,57 +2461,57 @@ Interpreter::Sparse_subtract_SA_SB(const mxArray *A_m, const mxArray *B_m)
   return C_m;
 }
 
-mxArray *
-Interpreter::mult_SAT_B(const mxArray *A_m, const mxArray *B_m)
+mxArray*
+Interpreter::mult_SAT_B(const mxArray* A_m, const mxArray* B_m)
 {
   size_t n_A = mxGetN(A_m);
-  mwIndex *A_i = mxGetIr(A_m);
-  mwIndex *A_j = mxGetJc(A_m);
-  double *A_d = mxGetPr(A_m);
+  mwIndex* A_i = mxGetIr(A_m);
+  mwIndex* A_j = mxGetJc(A_m);
+  double* A_d = mxGetPr(A_m);
   size_t n_B = mxGetN(B_m);
-  double *B_d = mxGetPr(B_m);
-  mxArray *C_m = mxCreateDoubleMatrix(n_A, n_B, mxREAL);
-  double *C_d = mxGetPr(C_m);
+  double* B_d = mxGetPr(B_m);
+  mxArray* C_m = mxCreateDoubleMatrix(n_A, n_B, mxREAL);
+  double* C_d = mxGetPr(C_m);
   for (int j = 0; j < static_cast<int>(n_B); j++)
     for (unsigned int i = 0; i < n_A; i++)
       {
         double sum = 0;
         size_t nze_A = A_j[i];
-        while (nze_A < static_cast<unsigned int>(A_j[i+1]))
+        while (nze_A < static_cast<unsigned int>(A_j[i + 1]))
           {
             size_t i_A = A_i[nze_A];
             sum += A_d[nze_A++] * B_d[i_A];
           }
-        C_d[j*n_A+i] = sum;
+        C_d[j * n_A + i] = sum;
       }
   return C_m;
 }
 
-mxArray *
-Interpreter::Sparse_mult_SAT_B(const mxArray *A_m, const mxArray *B_m)
+mxArray*
+Interpreter::Sparse_mult_SAT_B(const mxArray* A_m, const mxArray* B_m)
 {
   size_t n_A = mxGetN(A_m);
-  mwIndex *A_i = mxGetIr(A_m);
-  mwIndex *A_j = mxGetJc(A_m);
-  double *A_d = mxGetPr(A_m);
+  mwIndex* A_i = mxGetIr(A_m);
+  mwIndex* A_j = mxGetJc(A_m);
+  double* A_d = mxGetPr(A_m);
   size_t n_B = mxGetN(B_m);
   size_t m_B = mxGetM(B_m);
-  double *B_d = mxGetPr(B_m);
-  mxArray *C_m = mxCreateSparse(n_A, n_B, n_A*n_B, mxREAL);
-  mwIndex *C_i = mxGetIr(C_m);
-  mwIndex *C_j = mxGetJc(C_m);
-  double *C_d = mxGetPr(C_m);
+  double* B_d = mxGetPr(B_m);
+  mxArray* C_m = mxCreateSparse(n_A, n_B, n_A * n_B, mxREAL);
+  mwIndex* C_i = mxGetIr(C_m);
+  mwIndex* C_j = mxGetJc(C_m);
+  double* C_d = mxGetPr(C_m);
   unsigned int nze_C = 0;
-  //unsigned int nze_A = 0;
+  // unsigned int nze_A = 0;
   unsigned int C_col = 0;
   C_j[C_col] = 0;
-  //#pragma omp parallel for
+  // #pragma omp parallel for
   for (unsigned int j = 0; j < n_B; j++)
     for (unsigned int i = 0; i < n_A; i++)
       {
         double sum = 0;
         size_t nze_A = A_j[i];
-        while (nze_A < static_cast<unsigned int>(A_j[i+1]))
+        while (nze_A < static_cast<unsigned int>(A_j[i + 1]))
           {
             size_t i_A = A_i[nze_A];
             sum += A_d[nze_A++] * B_d[i_A];
@@ -2467,21 +2531,21 @@ Interpreter::Sparse_mult_SAT_B(const mxArray *A_m, const mxArray *B_m)
   return C_m;
 }
 
-mxArray *
-Interpreter::Sparse_mult_SAT_SB(const mxArray *A_m, const mxArray *B_m)
+mxArray*
+Interpreter::Sparse_mult_SAT_SB(const mxArray* A_m, const mxArray* B_m)
 {
   size_t n_A = mxGetN(A_m);
-  mwIndex *A_i = mxGetIr(A_m);
-  mwIndex *A_j = mxGetJc(A_m);
-  double *A_d = mxGetPr(A_m);
+  mwIndex* A_i = mxGetIr(A_m);
+  mwIndex* A_j = mxGetJc(A_m);
+  double* A_d = mxGetPr(A_m);
   size_t n_B = mxGetN(B_m);
-  mwIndex *B_i = mxGetIr(B_m);
-  mwIndex *B_j = mxGetJc(B_m);
-  double *B_d = mxGetPr(B_m);
-  mxArray *C_m = mxCreateSparse(n_A, n_B, n_A*n_B, mxREAL);
-  mwIndex *C_i = mxGetIr(C_m);
-  mwIndex *C_j = mxGetJc(C_m);
-  double *C_d = mxGetPr(C_m);
+  mwIndex* B_i = mxGetIr(B_m);
+  mwIndex* B_j = mxGetJc(B_m);
+  double* B_d = mxGetPr(B_m);
+  mxArray* C_m = mxCreateSparse(n_A, n_B, n_A * n_B, mxREAL);
+  mwIndex* C_i = mxGetIr(C_m);
+  mwIndex* C_j = mxGetJc(C_m);
+  double* C_d = mxGetPr(C_m);
   size_t nze_B = 0, nze_C = 0, nze_A = 0;
   unsigned int C_col = 0;
   C_j[C_col] = 0;
@@ -2491,7 +2555,8 @@ Interpreter::Sparse_mult_SAT_SB(const mxArray *A_m, const mxArray *B_m)
         double sum = 0;
         nze_B = B_j[j];
         nze_A = A_j[i];
-        while (nze_A < static_cast<unsigned int>(A_j[i+1]) && nze_B < static_cast<unsigned int>(B_j[j+1]))
+        while (nze_A < static_cast<unsigned int>(A_j[i + 1])
+               && nze_B < static_cast<unsigned int>(B_j[j + 1]))
           {
             size_t i_A = A_i[nze_A];
             size_t i_B = B_i[nze_B];
@@ -2517,32 +2582,32 @@ Interpreter::Sparse_mult_SAT_SB(const mxArray *A_m, const mxArray *B_m)
   return C_m;
 }
 
-mxArray *
-Interpreter::Sparse_transpose(const mxArray *A_m)
+mxArray*
+Interpreter::Sparse_transpose(const mxArray* A_m)
 {
   size_t n_A = mxGetN(A_m);
   size_t m_A = mxGetM(A_m);
-  mwIndex *A_i = mxGetIr(A_m);
-  mwIndex *A_j = mxGetJc(A_m);
+  mwIndex* A_i = mxGetIr(A_m);
+  mwIndex* A_j = mxGetJc(A_m);
   size_t total_nze_A = A_j[n_A];
-  double *A_d = mxGetPr(A_m);
-  mxArray *C_m = mxCreateSparse(n_A, m_A, total_nze_A, mxREAL);
-  mwIndex *C_i = mxGetIr(C_m);
-  mwIndex *C_j = mxGetJc(C_m);
-  double *C_d = mxGetPr(C_m);
+  double* A_d = mxGetPr(A_m);
+  mxArray* C_m = mxCreateSparse(n_A, m_A, total_nze_A, mxREAL);
+  mwIndex* C_i = mxGetIr(C_m);
+  mwIndex* C_j = mxGetJc(C_m);
+  double* C_d = mxGetPr(C_m);
   unsigned int nze_C = 0, nze_A = 0;
-  fill_n(C_j, m_A+1, 0);
+  fill_n(C_j, m_A + 1, 0);
   map<pair<mwIndex, unsigned int>, double> B2;
   for (unsigned int i = 0; i < n_A; i++)
-    while (nze_A < static_cast<unsigned int>(A_j[i+1]))
+    while (nze_A < static_cast<unsigned int>(A_j[i + 1]))
       {
-        C_j[A_i[nze_A]+1]++;
-        B2[{ A_i[nze_A], i }] = A_d[nze_A];
+        C_j[A_i[nze_A] + 1]++;
+        B2[{A_i[nze_A], i}] = A_d[nze_A];
         nze_A++;
       }
   for (unsigned int i = 0; i < m_A; i++)
-    C_j[i+1] += C_j[i];
-  for (auto &[key, val] : B2)
+    C_j[i + 1] += C_j[i];
+  for (auto& [key, val] : B2)
     {
       C_d[nze_C] = val;
       C_i[nze_C++] = key.second;
@@ -2569,9 +2634,11 @@ Interpreter::compute_block_time(int my_Per_u_, bool evaluate, bool no_derivative
 
   try
     {
-      evaluator.evaluateBlock(it_, y_kmin, y, y_size, x, nb_row_x, params, steady_y, u, my_Per_u_, T, periods, TEF, TEFD, TEFDD, r, g1, jacob, jacob_exo, jacob_exo_det, evaluate, no_derivatives);
+      evaluator.evaluateBlock(it_, y_kmin, y, y_size, x, nb_row_x, params, steady_y, u, my_Per_u_,
+                              T, periods, TEF, TEFD, TEFDD, r, g1, jacob, jacob_exo, jacob_exo_det,
+                              evaluate, no_derivatives);
     }
-  catch (FloatingPointException &e)
+  catch (FloatingPointException& e)
     {
       res1 = numeric_limits<double>::quiet_NaN();
       if (verbosity >= 2)
@@ -2599,7 +2666,7 @@ Interpreter::compute_complete(bool no_derivatives)
               max_res = fabs(rr);
               max_res_idx = i;
             }
-          res2 += rr*rr;
+          res2 += rr * rr;
           res1 += fabs(rr);
         }
       result = true;
@@ -2627,20 +2694,20 @@ Interpreter::compute_complete(double lambda)
       if (compute_complete(true))
         res2_ = res2;
       else
-        return { false, numeric_limits<double>::quiet_NaN() };
+        return {false, numeric_limits<double>::quiet_NaN()};
     }
   else
     {
-      for (int it = y_kmin; it < periods+y_kmin; it++)
+      for (int it = y_kmin; it < periods + y_kmin; it++)
         for (int i = 0; i < size; i++)
           {
             int eq = index_vara[i];
-            y[eq+it*y_size] = ya[eq+it*y_size] + lambda * direction[eq+it*y_size];
+            y[eq + it * y_size] = ya[eq + it * y_size] + lambda * direction[eq + it * y_size];
           }
-      for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
+      for (it_ = y_kmin; it_ < periods + y_kmin; it_++)
         {
-          Per_u_ = (it_-y_kmin)*u_count_int;
-          Per_y_ = it_*y_size;
+          Per_u_ = (it_ - y_kmin) * u_count_int;
+          Per_y_ = it_ * y_size;
           if (compute_complete(true))
             {
               res2_ += res2;
@@ -2652,27 +2719,26 @@ Interpreter::compute_complete(double lambda)
                 }
             }
           else
-            return { false, numeric_limits<double>::quiet_NaN() };
+            return {false, numeric_limits<double>::quiet_NaN()};
         }
-      it_ = periods+y_kmin-1; // Do not leave it_ in inconsistent state
+      it_ = periods + y_kmin - 1; // Do not leave it_ in inconsistent state
     }
   if (verbosity >= 2)
     mexPrintf("  lambda=%e, res2=%e\n", lambda, res2_);
-  double crit {res2_/2};
-  return { true, crit };
+  double crit {res2_ / 2};
+  return {true, crit};
 }
 
 tuple<bool, double, double, double, double>
-Interpreter::mnbrak(double &ax, double &bx)
+Interpreter::mnbrak(double& ax, double& bx)
 {
   constexpr double GOLD = 1.618034;
   constexpr double GLIMIT = 100.0;
   constexpr double TINY = 1.0e-20;
 
-  constexpr tuple failval = { false, numeric_limits<double>::quiet_NaN(),
-                              numeric_limits<double>::quiet_NaN(),
-                              numeric_limits<double>::quiet_NaN(),
-                              numeric_limits<double>::quiet_NaN() };
+  constexpr tuple failval
+      = {false, numeric_limits<double>::quiet_NaN(), numeric_limits<double>::quiet_NaN(),
+         numeric_limits<double>::quiet_NaN(), numeric_limits<double>::quiet_NaN()};
 
   auto sign = [](double a, double b) { return b >= 0.0 ? fabs(a) : -fabs(a); };
 
@@ -2693,20 +2759,20 @@ Interpreter::mnbrak(double &ax, double &bx)
       swap(fa, fb);
     }
 
-  double cx = bx+GOLD*(bx-ax);
+  double cx = bx + GOLD * (bx - ax);
   auto [success3, fc] = compute_complete(cx);
   if (!success3)
     return failval;
 
   while (fb > fc)
     {
-      double r = (bx-ax)*(fb-fc);
-      double q = (bx-cx)*(fb-fa);
-      double u = bx-((bx-cx)*q-(bx-ax)*r)
-        /(2.0*sign(fmax(fabs(q-r), TINY), q-r));
-      double ulim = bx+GLIMIT*(cx-bx);
+      double r = (bx - ax) * (fb - fc);
+      double q = (bx - cx) * (fb - fa);
+      double u
+          = bx - ((bx - cx) * q - (bx - ax) * r) / (2.0 * sign(fmax(fabs(q - r), TINY), q - r));
+      double ulim = bx + GLIMIT * (cx - bx);
       double fu;
-      if ((bx-u)*(u-cx) > 0.0)
+      if ((bx - u) * (u - cx) > 0.0)
         {
           tie(success, fu) = compute_complete(u);
           if (!success)
@@ -2725,12 +2791,12 @@ Interpreter::mnbrak(double &ax, double &bx)
               fc = fu;
               goto success;
             }
-          u = cx+GOLD*(cx-bx);
+          u = cx + GOLD * (cx - bx);
           tie(success, fu) = compute_complete(u);
           if (!success)
             return failval;
         }
-      else if ((cx-u)*(u-ulim) > 0.0)
+      else if ((cx - u) * (u - ulim) > 0.0)
         {
           tie(success, fu) = compute_complete(u);
           if (!success)
@@ -2739,7 +2805,7 @@ Interpreter::mnbrak(double &ax, double &bx)
             {
               bx = cx;
               cx = u;
-              u = cx+GOLD*(cx-bx);
+              u = cx + GOLD * (cx - bx);
               fb = fc;
               fc = fu;
               tie(success, fu) = compute_complete(u);
@@ -2747,7 +2813,7 @@ Interpreter::mnbrak(double &ax, double &bx)
                 return failval;
             }
         }
-      else if ((u-ulim)*(ulim-cx) >= 0.0)
+      else if ((u - ulim) * (ulim - cx) >= 0.0)
         {
           u = ulim;
           tie(success, fu) = compute_complete(u);
@@ -2756,7 +2822,7 @@ Interpreter::mnbrak(double &ax, double &bx)
         }
       else
         {
-          u = cx+GOLD*(cx-bx);
+          u = cx + GOLD * (cx - bx);
           tie(success, fu) = compute_complete(u);
           if (!success)
             return failval;
@@ -2769,31 +2835,31 @@ Interpreter::mnbrak(double &ax, double &bx)
       fc = fu;
     }
 
- success:
-  return { true, cx, fa, fb, fc };
+success:
+  return {true, cx, fa, fb, fc};
 }
 
 pair<bool, double>
 Interpreter::golden(double ax, double bx, double cx, double tol)
 {
-  constexpr pair failval = { false, numeric_limits<double>::quiet_NaN() };
+  constexpr pair failval = {false, numeric_limits<double>::quiet_NaN()};
   const double R = 0.61803399;
-  const double C = (1.0-R);
+  const double C = (1.0 - R);
   if (verbosity >= 2)
     mexPrintf("golden\n");
   int iter = 0, max_iter = 100;
   double x1, x2;
   double x0 = ax;
   double x3 = cx;
-  if (fabs(cx-bx) > fabs(bx-ax))
+  if (fabs(cx - bx) > fabs(bx - ax))
     {
       x1 = bx;
-      x2 = bx+C*(cx-bx);
+      x2 = bx + C * (cx - bx);
     }
   else
     {
       x2 = bx;
-      x1 = bx-C*(bx-ax);
+      x1 = bx - C * (bx - ax);
     }
   auto [success, f1] = compute_complete(x1);
   if (!success)
@@ -2801,14 +2867,14 @@ Interpreter::golden(double ax, double bx, double cx, double tol)
   auto [success2, f2] = compute_complete(x2);
   if (!success2)
     return failval;
-  while (fabs(x3-x0) > tol*(fabs(x1)+fabs(x2)) && f1 > solve_tolf && f2 > solve_tolf
+  while (fabs(x3 - x0) > tol * (fabs(x1) + fabs(x2)) && f1 > solve_tolf && f2 > solve_tolf
          && iter < max_iter && abs(x1 - x2) > 1e-4)
     {
       if (f2 < f1)
         {
           x0 = x1;
           x1 = x2;
-          x2 = R*x1+C*x3;
+          x2 = R * x1 + C * x3;
           f1 = f2;
           tie(success, f2) = compute_complete(x2);
           if (!success)
@@ -2818,7 +2884,7 @@ Interpreter::golden(double ax, double bx, double cx, double tol)
         {
           x3 = x2;
           x2 = x1;
-          x1 = R*x2+C*x0;
+          x1 = R * x2 + C * x0;
           f2 = f1;
           tie(success, f1) = compute_complete(x1);
           if (!success)
@@ -2826,8 +2892,8 @@ Interpreter::golden(double ax, double bx, double cx, double tol)
         }
       iter++;
     }
-  double xmin { f1 < f2 ? x1 : x2 };
-  return { true, xmin };
+  double xmin {f1 < f2 ? x1 : x2};
+  return {true, xmin};
 }
 
 void
@@ -2850,9 +2916,11 @@ Interpreter::End_Solver()
 }
 
 void
-Interpreter::Solve_LU_UMFPack_Two_Boundaries(SuiteSparse_long *Ap, SuiteSparse_long *Ai, double *Ax, double *b, const vector_table_conditional_local_type &vector_table_conditional_local)
+Interpreter::Solve_LU_UMFPack_Two_Boundaries(
+    SuiteSparse_long* Ap, SuiteSparse_long* Ai, double* Ax, double* b,
+    const vector_table_conditional_local_type& vector_table_conditional_local)
 {
-  int n { size*periods };
+  int n {size * periods};
   SuiteSparse_long sys = 0;
   double Control[UMFPACK_CONTROL], Info[UMFPACK_INFO], res[n];
 
@@ -2867,7 +2935,7 @@ Interpreter::Solve_LU_UMFPack_Two_Boundaries(SuiteSparse_long *Ap, SuiteSparse_l
         {
           umfpack_dl_report_info(Control, Info);
           umfpack_dl_report_status(Control, status);
-          throw FatalException{"umfpack_dl_symbolic failed"};
+          throw FatalException {"umfpack_dl_symbolic failed"};
         }
     }
   if (Numeric)
@@ -2877,14 +2945,14 @@ Interpreter::Solve_LU_UMFPack_Two_Boundaries(SuiteSparse_long *Ap, SuiteSparse_l
     {
       umfpack_dl_report_info(Control, Info);
       umfpack_dl_report_status(Control, status);
-      throw FatalException{"umfpack_dl_numeric failed"};
+      throw FatalException {"umfpack_dl_numeric failed"};
     }
   status = umfpack_dl_solve(sys, Ap, Ai, Ax, res, b, Numeric, Control, Info);
   if (status != UMFPACK_OK)
     {
       umfpack_dl_report_info(Control, Info);
       umfpack_dl_report_status(Control, status);
-      throw FatalException{"umfpack_dl_solve failed"};
+      throw FatalException {"umfpack_dl_solve failed"};
     }
 
   if (vector_table_conditional_local.size())
@@ -2897,15 +2965,15 @@ Interpreter::Solve_LU_UMFPack_Two_Boundaries(SuiteSparse_long *Ap, SuiteSparse_l
                 bool fliped = vector_table_conditional_local[i].is_cond;
                 if (fliped)
                   {
-                    int eq = index_vara[i+size*(y_kmin)];
+                    int eq = index_vara[i + size * (y_kmin)];
                     int flip_exo = vector_table_conditional_local[i].var_exo;
-                    double yy = -(res[i] + x[y_kmin + flip_exo*nb_row_x]);
+                    double yy = -(res[i] + x[y_kmin + flip_exo * nb_row_x]);
                     direction[eq] = 0;
-                    x[flip_exo*nb_row_x + y_kmin] += slowc * yy;
+                    x[flip_exo * nb_row_x + y_kmin] += slowc * yy;
                   }
                 else
                   {
-                    int eq = index_vara[i+size*(y_kmin)];
+                    int eq = index_vara[i + size * (y_kmin)];
                     double yy = -(res[i] + y[eq]);
                     direction[eq] = yy;
                     y[eq] += slowc * yy;
@@ -2916,7 +2984,7 @@ Interpreter::Solve_LU_UMFPack_Two_Boundaries(SuiteSparse_long *Ap, SuiteSparse_l
           {
             for (int i = 0; i < size; i++)
               {
-                int eq = index_vara[i+size*(t + y_kmin)];
+                int eq = index_vara[i + size * (t + y_kmin)];
                 double yy = -(res[i + size * t] + y[eq]);
                 direction[eq] = yy;
                 y[eq] += slowc * yy;
@@ -2927,7 +2995,7 @@ Interpreter::Solve_LU_UMFPack_Two_Boundaries(SuiteSparse_long *Ap, SuiteSparse_l
     {
       for (int i = 0; i < n; i++)
         {
-          int eq = index_vara[i+size*y_kmin];
+          int eq = index_vara[i + size * y_kmin];
           double yy = -(res[i] + y[eq]);
           direction[eq] = yy;
           y[eq] += slowc * yy;
@@ -2941,7 +3009,8 @@ Interpreter::Solve_LU_UMFPack_Two_Boundaries(SuiteSparse_long *Ap, SuiteSparse_l
 }
 
 void
-Interpreter::Solve_LU_UMFPack_One_Boundary(SuiteSparse_long *Ap, SuiteSparse_long *Ai, double *Ax, double *b)
+Interpreter::Solve_LU_UMFPack_One_Boundary(SuiteSparse_long* Ap, SuiteSparse_long* Ai, double* Ax,
+                                           double* b)
 {
   SuiteSparse_long sys = 0;
   double Control[UMFPACK_CONTROL], Info[UMFPACK_INFO], res[size];
@@ -2957,7 +3026,7 @@ Interpreter::Solve_LU_UMFPack_One_Boundary(SuiteSparse_long *Ap, SuiteSparse_lon
         {
           umfpack_dl_report_info(Control, Info);
           umfpack_dl_report_status(Control, status);
-          throw FatalException{"umfpack_dl_symbolic failed"};
+          throw FatalException {"umfpack_dl_symbolic failed"};
         }
     }
   if (Numeric)
@@ -2967,22 +3036,22 @@ Interpreter::Solve_LU_UMFPack_One_Boundary(SuiteSparse_long *Ap, SuiteSparse_lon
     {
       umfpack_dl_report_info(Control, Info);
       umfpack_dl_report_status(Control, status);
-      throw FatalException{"umfpack_dl_numeric failed"};
+      throw FatalException {"umfpack_dl_numeric failed"};
     }
   status = umfpack_dl_solve(sys, Ap, Ai, Ax, res, b, Numeric, Control, Info);
   if (status != UMFPACK_OK)
     {
       umfpack_dl_report_info(Control, Info);
       umfpack_dl_report_status(Control, status);
-      throw FatalException{"umfpack_dl_solve failed"};
+      throw FatalException {"umfpack_dl_solve failed"};
     }
 
   for (int i = 0; i < size; i++)
     {
       int eq = index_vara[i];
-      double yy = -(res[i] + y[eq+it_*y_size]);
+      double yy = -(res[i] + y[eq + it_ * y_size]);
       direction[eq] = yy;
-      y[eq+it_*y_size] += slowc * yy;
+      y[eq + it_ * y_size] += slowc * yy;
     }
   mxFree(Ap);
   mxFree(Ai);
@@ -2991,28 +3060,35 @@ Interpreter::Solve_LU_UMFPack_One_Boundary(SuiteSparse_long *Ap, SuiteSparse_lon
 }
 
 void
-Interpreter::Solve_Matlab_GMRES(mxArray *A_m, mxArray *b_m, bool is_two_boundaries, mxArray *x0_m)
+Interpreter::Solve_Matlab_GMRES(mxArray* A_m, mxArray* b_m, bool is_two_boundaries, mxArray* x0_m)
 {
   size_t n = mxGetM(A_m);
-  const char *field_names[] = {"droptol", "type"};
-  mwSize dims[1] = { 1 };
-  mxArray *Setup = mxCreateStructArray(1, dims, std::extent_v<decltype(field_names)>, field_names);
+  const char* field_names[] = {"droptol", "type"};
+  mwSize dims[1] = {1};
+  mxArray* Setup = mxCreateStructArray(1, dims, std::extent_v<decltype(field_names)>, field_names);
   mxSetFieldByNumber(Setup, 0, 0, mxCreateDoubleScalar(lu_inc_tol));
   mxSetFieldByNumber(Setup, 0, 1, mxCreateString("ilutp"));
-  mxArray *lhs0[2];
-   mxArray *rhs0[] = { A_m, Setup };
-  if (mexCallMATLAB(std::extent_v<decltype(lhs0)>, lhs0, std::extent_v<decltype(rhs0)>, rhs0, "ilu"))
+  mxArray* lhs0[2];
+  mxArray* rhs0[] = {A_m, Setup};
+  if (mexCallMATLAB(std::extent_v<decltype(lhs0)>, lhs0, std::extent_v<decltype(rhs0)>, rhs0,
+                    "ilu"))
     throw FatalException("In GMRES, the incomplete LU decomposition (ilu) has failed");
-  mxArray *L1 = lhs0[0];
-  mxArray *U1 = lhs0[1];
+  mxArray* L1 = lhs0[0];
+  mxArray* U1 = lhs0[1];
   /*[za,flag1] = gmres(g1a,b,Blck_size,1e-6,Blck_size*periods,L1,U1);*/
-  mxArray *rhs[] = { A_m, b_m, mxCreateDoubleScalar(size), mxCreateDoubleScalar(1e-6),
-    mxCreateDoubleScalar(static_cast<double>(n)), L1, U1, x0_m };
-  mxArray *lhs[2];
+  mxArray* rhs[] = {A_m,
+                    b_m,
+                    mxCreateDoubleScalar(size),
+                    mxCreateDoubleScalar(1e-6),
+                    mxCreateDoubleScalar(static_cast<double>(n)),
+                    L1,
+                    U1,
+                    x0_m};
+  mxArray* lhs[2];
   mexCallMATLAB(std::extent_v<decltype(lhs)>, lhs, std::extent_v<decltype(rhs)>, rhs, "gmres");
-  mxArray *z = lhs[0];
-  mxArray *flag = lhs[1];
-  double flag1 { mxGetScalar(flag) };
+  mxArray* z = lhs[0];
+  mxArray* flag = lhs[1];
+  double flag1 {mxGetScalar(flag)};
   mxDestroyArray(rhs0[1]);
   mxDestroyArray(rhs[2]);
   mxDestroyArray(rhs[3]);
@@ -3022,23 +3098,27 @@ Interpreter::Solve_Matlab_GMRES(mxArray *A_m, mxArray *b_m, bool is_two_boundari
   if (flag1 > 0)
     {
       if (flag1 == 1)
-        mexWarnMsgTxt(("Error in bytecode: No convergence inside GMRES, in block "
-                       + to_string(block_num+1)).c_str());
+        mexWarnMsgTxt(
+            ("Error in bytecode: No convergence inside GMRES, in block " + to_string(block_num + 1))
+                .c_str());
       else if (flag1 == 2)
         mexWarnMsgTxt(("Error in bytecode: Preconditioner is ill-conditioned, in block "
-                       + to_string(block_num+1)).c_str());
+                       + to_string(block_num + 1))
+                          .c_str());
       else if (flag1 == 3)
-        mexWarnMsgTxt(("Error in bytecode: GMRES stagnated (Two consecutive iterates were the same.), in block "
-                       + to_string(block_num+1)).c_str());
+        mexWarnMsgTxt(("Error in bytecode: GMRES stagnated (Two consecutive iterates were the "
+                       "same.), in block "
+                       + to_string(block_num + 1))
+                          .c_str());
       lu_inc_tol /= 10;
     }
   else
     {
-      double *res = mxGetPr(z);
+      double* res = mxGetPr(z);
       if (is_two_boundaries)
         for (int i = 0; i < static_cast<int>(n); i++)
           {
-            int eq = index_vara[i+size*y_kmin];
+            int eq = index_vara[i + size * y_kmin];
             double yy = -(res[i] + y[eq]);
             direction[eq] = yy;
             y[eq] += slowc * yy;
@@ -3047,9 +3127,9 @@ Interpreter::Solve_Matlab_GMRES(mxArray *A_m, mxArray *b_m, bool is_two_boundari
         for (int i = 0; i < static_cast<int>(n); i++)
           {
             int eq = index_vara[i];
-            double yy = -(res[i] + y[eq+it_*y_size]);
+            double yy = -(res[i] + y[eq + it_ * y_size]);
             direction[eq] = yy;
-            y[eq+it_*y_size] += slowc * yy;
+            y[eq + it_ * y_size] += slowc * yy;
           }
     }
   mxDestroyArray(A_m);
@@ -3060,7 +3140,8 @@ Interpreter::Solve_Matlab_GMRES(mxArray *A_m, mxArray *b_m, bool is_two_boundari
 }
 
 void
-Interpreter::Solve_Matlab_BiCGStab(mxArray *A_m, mxArray *b_m, bool is_two_boundaries, mxArray *x0_m, int preconditioner)
+Interpreter::Solve_Matlab_BiCGStab(mxArray* A_m, mxArray* b_m, bool is_two_boundaries,
+                                   mxArray* x0_m, int preconditioner)
 {
   /* precond = 0  => Jacobi
      precond = 1  => Incomplet LU decomposition*/
@@ -3069,15 +3150,16 @@ Interpreter::Solve_Matlab_BiCGStab(mxArray *A_m, mxArray *b_m, bool is_two_bound
 
   if (preconditioner == 0)
     {
-      mxArray *lhs0[1];
-      mxArray *rhs0[] = { A_m, mxCreateDoubleScalar(0) };
-      mexCallMATLAB(std::extent_v<decltype(lhs0)>, lhs0, std::extent_v<decltype(rhs0)>, rhs0, "spdiags");
-      mxArray *tmp = lhs0[0];
-      double *tmp_val = mxGetPr(tmp);
+      mxArray* lhs0[1];
+      mxArray* rhs0[] = {A_m, mxCreateDoubleScalar(0)};
+      mexCallMATLAB(std::extent_v<decltype(lhs0)>, lhs0, std::extent_v<decltype(rhs0)>, rhs0,
+                    "spdiags");
+      mxArray* tmp = lhs0[0];
+      double* tmp_val = mxGetPr(tmp);
       Diag = mxCreateSparse(n, n, n, mxREAL);
-      mwIndex *Diag_i = mxGetIr(Diag);
-      mwIndex *Diag_j = mxGetJc(Diag);
-      double *Diag_val = mxGetPr(Diag);
+      mwIndex* Diag_i = mxGetIr(Diag);
+      mwIndex* Diag_j = mxGetJc(Diag);
+      double* Diag_val = mxGetPr(Diag);
       for (size_t i = 0; i < n; i++)
         {
           Diag_val[i] = tmp_val[i];
@@ -3089,40 +3171,45 @@ Interpreter::Solve_Matlab_BiCGStab(mxArray *A_m, mxArray *b_m, bool is_two_bound
   else if (preconditioner == 1)
     {
       /*[L1, U1] = ilu(g1a=;*/
-      const char *field_names[] = {"type", "droptol", "milu", "udiag", "thresh"};
+      const char* field_names[] = {"type", "droptol", "milu", "udiag", "thresh"};
       const int type = 0, droptol = 1, milu = 2, udiag = 3, thresh = 4;
-      mwSize dims[1] = { static_cast<mwSize>(1) };
-      mxArray *Setup = mxCreateStructArray(1, dims, std::extent_v<decltype(field_names)>, field_names);
+      mwSize dims[1] = {static_cast<mwSize>(1)};
+      mxArray* Setup
+          = mxCreateStructArray(1, dims, std::extent_v<decltype(field_names)>, field_names);
       mxSetFieldByNumber(Setup, 0, type, mxCreateString("ilutp"));
       mxSetFieldByNumber(Setup, 0, droptol, mxCreateDoubleScalar(lu_inc_tol));
       mxSetFieldByNumber(Setup, 0, milu, mxCreateString("off"));
       mxSetFieldByNumber(Setup, 0, udiag, mxCreateDoubleScalar(0));
       mxSetFieldByNumber(Setup, 0, thresh, mxCreateDoubleScalar(1));
-      mxArray *lhs0[2];
-      mxArray *rhs0[] = { A_m, Setup };
-      if (mexCallMATLAB(std::extent_v<decltype(lhs0)>, lhs0, std::extent_v<decltype(rhs0)>, rhs0, "ilu"))
-        throw FatalException{"In BiCGStab, the incomplete LU decomposition (ilu) has failed"};
+      mxArray* lhs0[2];
+      mxArray* rhs0[] = {A_m, Setup};
+      if (mexCallMATLAB(std::extent_v<decltype(lhs0)>, lhs0, std::extent_v<decltype(rhs0)>, rhs0,
+                        "ilu"))
+        throw FatalException {"In BiCGStab, the incomplete LU decomposition (ilu) has failed"};
       L1 = lhs0[0];
       U1 = lhs0[1];
       mxDestroyArray(Setup);
     }
   double flags = 2;
-  mxArray *z = nullptr;
-  if (steady_state) /*Octave BicStab algorihtm involves a 0 division in case of a preconditionner equal to the LU decomposition of A matrix*/
+  mxArray* z = nullptr;
+  if (steady_state) /*Octave BicStab algorihtm involves a 0 division in case of a preconditionner
+                       equal to the LU decomposition of A matrix*/
     {
-      mxArray *res = mult_SAT_B(Sparse_transpose(A_m), x0_m);
-      double *resid = mxGetPr(res);
-      double *b = mxGetPr(b_m);
+      mxArray* res = mult_SAT_B(Sparse_transpose(A_m), x0_m);
+      double* resid = mxGetPr(res);
+      double* b = mxGetPr(b_m);
       for (int i = 0; i < static_cast<int>(n); i++)
         resid[i] = b[i] - resid[i];
-      mxArray *lhs[1];
-      mxArray *rhs[] = { L1, res };
-      mexCallMATLAB(std::extent_v<decltype(lhs)>, lhs, std::extent_v<decltype(rhs)>, rhs, "mldivide");
-      mxArray *rhs2[] = { U1, lhs[0] };
-      mexCallMATLAB(std::extent_v<decltype(lhs)>, lhs, std::extent_v<decltype(rhs2)>, rhs2, "mldivide");
+      mxArray* lhs[1];
+      mxArray* rhs[] = {L1, res};
+      mexCallMATLAB(std::extent_v<decltype(lhs)>, lhs, std::extent_v<decltype(rhs)>, rhs,
+                    "mldivide");
+      mxArray* rhs2[] = {U1, lhs[0]};
+      mexCallMATLAB(std::extent_v<decltype(lhs)>, lhs, std::extent_v<decltype(rhs2)>, rhs2,
+                    "mldivide");
       z = lhs[0];
-      double *phat = mxGetPr(z);
-      double *x0 = mxGetPr(x0_m);
+      double* phat = mxGetPr(z);
+      double* x0 = mxGetPr(x0_m);
       for (int i = 0; i < static_cast<int>(n); i++)
         phat[i] = x0[i] + phat[i];
 
@@ -3147,12 +3234,13 @@ Interpreter::Solve_Matlab_BiCGStab(mxArray *A_m, mxArray *b_m, bool is_two_bound
       if (preconditioner == 0)
         {
           /*[za,flag1] = bicgstab(g1a,b,1e-6,Blck_size*periods,L1,U1);*/
-          mxArray *rhs[] = { A_m, b_m, mxCreateDoubleScalar(1e-6),
-            mxCreateDoubleScalar(static_cast<double>(n)), Diag };
-          mxArray *lhs[2];
-          mexCallMATLAB(std::extent_v<decltype(lhs)>, lhs, std::extent_v<decltype(rhs)>, rhs, "bicgstab");
+          mxArray* rhs[] = {A_m, b_m, mxCreateDoubleScalar(1e-6),
+                            mxCreateDoubleScalar(static_cast<double>(n)), Diag};
+          mxArray* lhs[2];
+          mexCallMATLAB(std::extent_v<decltype(lhs)>, lhs, std::extent_v<decltype(rhs)>, rhs,
+                        "bicgstab");
           z = lhs[0];
-          mxArray *flag = lhs[1];
+          mxArray* flag = lhs[1];
           flags = mxGetScalar(flag);
           mxDestroyArray(flag);
           mxDestroyArray(rhs[2]);
@@ -3162,12 +3250,18 @@ Interpreter::Solve_Matlab_BiCGStab(mxArray *A_m, mxArray *b_m, bool is_two_bound
       else if (preconditioner == 1)
         {
           /*[za,flag1] = bicgstab(g1a,b,1e-6,Blck_size*periods,L1,U1);*/
-          mxArray *rhs[] = { A_m, b_m, mxCreateDoubleScalar(1e-6),
-            mxCreateDoubleScalar(static_cast<double>(n)), L1, U1, x0_m };
-          mxArray *lhs[2];
-          mexCallMATLAB(std::extent_v<decltype(lhs)>, lhs, std::extent_v<decltype(rhs)>, rhs, "bicgstab");
+          mxArray* rhs[] = {A_m,
+                            b_m,
+                            mxCreateDoubleScalar(1e-6),
+                            mxCreateDoubleScalar(static_cast<double>(n)),
+                            L1,
+                            U1,
+                            x0_m};
+          mxArray* lhs[2];
+          mexCallMATLAB(std::extent_v<decltype(lhs)>, lhs, std::extent_v<decltype(rhs)>, rhs,
+                        "bicgstab");
           z = lhs[0];
-          mxArray *flag = lhs[1];
+          mxArray* flag = lhs[1];
           flags = mxGetScalar(flag);
           mxDestroyArray(flag);
           mxDestroyArray(rhs[2]);
@@ -3181,22 +3275,26 @@ Interpreter::Solve_Matlab_BiCGStab(mxArray *A_m, mxArray *b_m, bool is_two_bound
     {
       if (flags == 1)
         mexWarnMsgTxt(("Error in bytecode: No convergence inside BiCGStab, in block "
-                       + to_string(block_num+1)).c_str());
+                       + to_string(block_num + 1))
+                          .c_str());
       else if (flags == 2)
         mexWarnMsgTxt(("Error in bytecode: Preconditioner is ill-conditioned, in block "
-                       + to_string(block_num+1)).c_str());
+                       + to_string(block_num + 1))
+                          .c_str());
       else if (flags == 3)
-        mexWarnMsgTxt(("Error in bytecode: BiCGStab stagnated (Two consecutive iterates were the same.), in block "
-                       + to_string(block_num+1)).c_str());
+        mexWarnMsgTxt(("Error in bytecode: BiCGStab stagnated (Two consecutive iterates were the "
+                       "same.), in block "
+                       + to_string(block_num + 1))
+                          .c_str());
       lu_inc_tol /= 10;
     }
   else
     {
-      double *res = mxGetPr(z);
+      double* res = mxGetPr(z);
       if (is_two_boundaries)
         for (int i = 0; i < static_cast<int>(n); i++)
           {
-            int eq = index_vara[i+size*y_kmin];
+            int eq = index_vara[i + size * y_kmin];
             double yy = -(res[i] + y[eq]);
             direction[eq] = yy;
             y[eq] += slowc * yy;
@@ -3205,9 +3303,9 @@ Interpreter::Solve_Matlab_BiCGStab(mxArray *A_m, mxArray *b_m, bool is_two_bound
         for (int i = 0; i < static_cast<int>(n); i++)
           {
             int eq = index_vara[i];
-            double yy = -(res[i] + y[eq+it_*y_size]);
+            double yy = -(res[i] + y[eq + it_ * y_size]);
             direction[eq] = yy;
-            y[eq+it_*y_size] += slowc * yy;
+            y[eq + it_ * y_size] += slowc * yy;
           }
     }
   mxDestroyArray(A_m);
@@ -3220,8 +3318,8 @@ void
 Interpreter::Singular_display()
 {
   Simple_Init();
-  mxArray *rhs[] = { mxCreateDoubleMatrix(size, size, mxREAL) };
-  double *pind = mxGetPr(rhs[0]);
+  mxArray* rhs[] = {mxCreateDoubleMatrix(size, size, mxREAL)};
+  double* pind = mxGetPr(rhs[0]);
   for (int j = 0; j < size * size; j++)
     pind[j] = 0.0;
   for (int ii = 0; ii < size; ii++)
@@ -3235,12 +3333,12 @@ Interpreter::Singular_display()
           first = first->NZE_C_N;
         }
     }
-  mxArray *lhs[3];
+  mxArray* lhs[3];
   mexCallMATLAB(std::extent_v<decltype(lhs)>, lhs, std::extent_v<decltype(rhs)>, rhs, "svd");
-  mxArray *SVD_u = lhs[0];
-  mxArray *SVD_s = lhs[1];
-  double *SVD_ps = mxGetPr(SVD_s);
-  double *SVD_pu = mxGetPr(SVD_u);
+  mxArray* SVD_u = lhs[0];
+  mxArray* SVD_s = lhs[1];
+  double* SVD_ps = mxGetPr(SVD_s);
+  double* SVD_pu = mxGetPr(SVD_u);
   for (int i = 0; i < size; i++)
     if (abs(SVD_ps[i * (1 + size)]) < 1e-12)
       {
@@ -3257,22 +3355,22 @@ Interpreter::Singular_display()
               {
                 equ_list.push_back(j);
                 if (rr != -1)
-                  mexPrintf(" - %3.2f*Dequ_%d_dy", abs(rr), j+1);
+                  mexPrintf(" - %3.2f*Dequ_%d_dy", abs(rr), j + 1);
                 else
-                  mexPrintf(" - Dequ_%d_dy", j+1);
+                  mexPrintf(" - Dequ_%d_dy", j + 1);
               }
             else if (rr > 1e-10)
               {
                 equ_list.push_back(j);
                 if (j > 0)
                   if (rr != 1)
-                    mexPrintf(" + %3.2f*Dequ_%d_dy", rr, j+1);
+                    mexPrintf(" + %3.2f*Dequ_%d_dy", rr, j + 1);
                   else
-                    mexPrintf(" + Dequ_%d_dy", j+1);
+                    mexPrintf(" + Dequ_%d_dy", j + 1);
                 else if (rr != 1)
-                  mexPrintf(" %3.2f*Dequ_%d_dy", rr, j+1);
+                  mexPrintf(" %3.2f*Dequ_%d_dy", rr, j + 1);
                 else
-                  mexPrintf(" Dequ_%d_dy", j+1);
+                  mexPrintf(" Dequ_%d_dy", j + 1);
               }
           }
         mexPrintf(" = 0\n");
@@ -3281,26 +3379,26 @@ Interpreter::Singular_display()
   mxDestroyArray(lhs[1]);
   mxDestroyArray(lhs[2]);
   if (block_num > 1)
-    throw FatalException{"In Solve_ByteCode_Sparse_GaussianElimination, singular system in block "
-                         + to_string(block_num+1)};
+    throw FatalException {"In Solve_ByteCode_Sparse_GaussianElimination, singular system in block "
+                          + to_string(block_num + 1)};
   else
-    throw FatalException{"In Solve_ByteCode_Sparse_GaussianElimination, singular system"};
+    throw FatalException {"In Solve_ByteCode_Sparse_GaussianElimination, singular system"};
 }
 
 bool
 Interpreter::Solve_ByteCode_Sparse_GaussianElimination()
 {
   int pivj = 0, pivk = 0;
-  NonZeroElem **bc = static_cast<NonZeroElem **>(mxMalloc(size*sizeof(*bc)));
-  test_mxMalloc(bc, __LINE__, __FILE__, __func__, size*sizeof(*bc));
-  double *piv_v = static_cast<double *>(mxMalloc(size*sizeof(double)));
-  test_mxMalloc(piv_v, __LINE__, __FILE__, __func__, size*sizeof(double));
-  int *pivj_v = static_cast<int *>(mxMalloc(size*sizeof(int)));
-  test_mxMalloc(pivj_v, __LINE__, __FILE__, __func__, size*sizeof(int));
-  int *pivk_v = static_cast<int *>(mxMalloc(size*sizeof(int)));
-  test_mxMalloc(pivk_v, __LINE__, __FILE__, __func__, size*sizeof(int));
-  int *NR = static_cast<int *>(mxMalloc(size*sizeof(int)));
-  test_mxMalloc(NR, __LINE__, __FILE__, __func__, size*sizeof(int));
+  NonZeroElem** bc = static_cast<NonZeroElem**>(mxMalloc(size * sizeof(*bc)));
+  test_mxMalloc(bc, __LINE__, __FILE__, __func__, size * sizeof(*bc));
+  double* piv_v = static_cast<double*>(mxMalloc(size * sizeof(double)));
+  test_mxMalloc(piv_v, __LINE__, __FILE__, __func__, size * sizeof(double));
+  int* pivj_v = static_cast<int*>(mxMalloc(size * sizeof(int)));
+  test_mxMalloc(pivj_v, __LINE__, __FILE__, __func__, size * sizeof(int));
+  int* pivk_v = static_cast<int*>(mxMalloc(size * sizeof(int)));
+  test_mxMalloc(pivk_v, __LINE__, __FILE__, __func__, size * sizeof(int));
+  int* NR = static_cast<int*>(mxMalloc(size * sizeof(int)));
+  test_mxMalloc(NR, __LINE__, __FILE__, __func__, size * sizeof(int));
 
   for (int i = 0; i < size; i++)
     {
@@ -3359,7 +3457,7 @@ Interpreter::Solve_ByteCode_Sparse_GaussianElimination()
               if (verbosity >= 1)
                 {
                   if (block_num > 1)
-                    mexPrintf("Error: singular system in Simulate_NG in block %d\n", block_num+1);
+                    mexPrintf("Error: singular system in Simulate_NG in block %d\n", block_num + 1);
                   else
                     mexPrintf("Error: singular system in Simulate_NG");
                 }
@@ -3368,10 +3466,12 @@ Interpreter::Solve_ByteCode_Sparse_GaussianElimination()
           else
             {
               if (block_num > 1)
-                throw FatalException{"In Solve_ByteCode_Sparse_GaussianElimination, singular system in block "
-                                     + to_string(block_num+1)};
+                throw FatalException {
+                    "In Solve_ByteCode_Sparse_GaussianElimination, singular system in block "
+                    + to_string(block_num + 1)};
               else
-                throw FatalException{"In Solve_ByteCode_Sparse_GaussianElimination, singular system"};
+                throw FatalException {
+                    "In Solve_ByteCode_Sparse_GaussianElimination, singular system"};
             }
         }
       double markovitz = 0, markovitz_max = -9e70;
@@ -3383,24 +3483,25 @@ Interpreter::Solve_ByteCode_Sparse_GaussianElimination()
                 if (fabs(piv_v[j]) > 0)
                   {
                     if (markowitz_c > 0)
-                      markovitz = exp(log(fabs(piv_v[j])/piv_abs)
-                                      -markowitz_c*log(static_cast<double>(NR[j])
-                                                       /static_cast<double>(N_max)));
+                      markovitz = exp(
+                          log(fabs(piv_v[j]) / piv_abs)
+                          - markowitz_c
+                                * log(static_cast<double>(NR[j]) / static_cast<double>(N_max)));
                     else
-                      markovitz = fabs(piv_v[j])/piv_abs;
-                    }
-                  else
-                    markovitz = 0;
-                }
-              else
-                markovitz = fabs(piv_v[j])/piv_abs;
-              if (markovitz > markovitz_max)
-                {
-                  piv = piv_v[j];
-                  pivj = pivj_v[j]; //Line number
-                  pivk = pivk_v[j]; //positi
-                  markovitz_max = markovitz;
-                }
+                      markovitz = fabs(piv_v[j]) / piv_abs;
+                  }
+                else
+                  markovitz = 0;
+              }
+            else
+              markovitz = fabs(piv_v[j]) / piv_abs;
+            if (markovitz > markovitz_max)
+              {
+                piv = piv_v[j];
+                pivj = pivj_v[j]; // Line number
+                pivk = pivk_v[j]; // positi
+                markovitz_max = markovitz;
+              }
           }
       else
         for (int j = 0; j < l; j++)
@@ -3410,22 +3511,23 @@ Interpreter::Solve_ByteCode_Sparse_GaussianElimination()
                 if (fabs(piv_v[j]) > 0)
                   {
                     if (markowitz_c > 0)
-                      markovitz = exp(log(fabs(piv_v[j])/piv_abs)
-                                      -markowitz_c*log(static_cast<double>(NR[j])
-                                                       /static_cast<double>(N_max)));
+                      markovitz = exp(
+                          log(fabs(piv_v[j]) / piv_abs)
+                          - markowitz_c
+                                * log(static_cast<double>(NR[j]) / static_cast<double>(N_max)));
                     else
-                      markovitz = fabs(piv_v[j])/piv_abs;
+                      markovitz = fabs(piv_v[j]) / piv_abs;
                   }
                 else
                   markovitz = 0;
               }
             else
-              markovitz = fabs(piv_v[j])/piv_abs;
+              markovitz = fabs(piv_v[j]) / piv_abs;
             if (NR[j] == 1)
               {
                 piv = piv_v[j];
-                pivj = pivj_v[j]; //Line number
-                pivk = pivk_v[j]; //positi
+                pivj = pivj_v[j]; // Line number
+                pivk = pivk_v[j]; // positi
                 markovitz_max = markovitz;
               }
           }
@@ -3460,7 +3562,7 @@ Interpreter::Solve_ByteCode_Sparse_GaussianElimination()
           double first_elem = u[first->u_index];
 
           int nb_var_piv = nb_var_piva;
-          NonZeroElem *first_piv = first_piva;
+          NonZeroElem* first_piv = first_piva;
           auto [nb_var_sub, first_sub] = At_Row(row);
           int l_sub = 0, l_piv = 0;
           int sub_c_index = first_sub->c_index, piv_c_index = first_piv->c_index;
@@ -3478,7 +3580,7 @@ Interpreter::Solve_ByteCode_Sparse_GaussianElimination()
               {
                 int tmp_u_count = Get_u();
                 Insert(row, first_piv->c_index, tmp_u_count, 0);
-                u[tmp_u_count] = -u[first_piv->u_index]*first_elem;
+                u[tmp_u_count] = -u[first_piv->u_index] * first_elem;
                 first_piv = first_piv->NZE_R_N;
                 if (first_piv)
                   piv_c_index = first_piv->c_index;
@@ -3490,8 +3592,8 @@ Interpreter::Solve_ByteCode_Sparse_GaussianElimination()
               {
                 if (i == sub_c_index)
                   {
-                    NonZeroElem *firsta = first;
-                    NonZeroElem *first_suba = first_sub->NZE_R_N;
+                    NonZeroElem* firsta = first;
+                    NonZeroElem* first_suba = first_sub->NZE_R_N;
                     Delete(first_sub->r_index, first_sub->c_index);
                     first = firsta->NZE_C_N;
                     first_sub = first_suba;
@@ -3509,7 +3611,7 @@ Interpreter::Solve_ByteCode_Sparse_GaussianElimination()
                   }
                 else
                   {
-                    u[first_sub->u_index] -= u[first_piv->u_index]*first_elem;
+                    u[first_sub->u_index] -= u[first_piv->u_index] * first_elem;
                     first_sub = first_sub->NZE_R_N;
                     if (first_sub)
                       sub_c_index = first_sub->c_index;
@@ -3524,11 +3626,11 @@ Interpreter::Solve_ByteCode_Sparse_GaussianElimination()
                     l_piv++;
                   }
               }
-          u[b[row]] -= u[b[pivj]]*first_elem;
+          u[b[row]] -= u[b[pivj]] * first_elem;
         }
     }
   for (int i = 0; i < y_size; i++)
-    ya[i+it_*y_size] = y[i+it_*y_size];
+    ya[i + it_ * y_size] = y[i + it_ * y_size];
 
   slowc_save = slowc;
   simple_bksub();
@@ -3552,34 +3654,34 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
   int pivj = 0, pivk = 0;
   int tbreak = 0, last_period = periods;
 
-  double *piv_v = static_cast<double *>(mxMalloc(size*sizeof(double)));
-  test_mxMalloc(piv_v, __LINE__, __FILE__, __func__, size*sizeof(double));
-  int *pivj_v = static_cast<int *>(mxMalloc(size*sizeof(int)));
-  test_mxMalloc(pivj_v, __LINE__, __FILE__, __func__, size*sizeof(int));
-  int *pivk_v = static_cast<int *>(mxMalloc(size*sizeof(int)));
-  test_mxMalloc(pivk_v, __LINE__, __FILE__, __func__, size*sizeof(int));
-  int *NR = static_cast<int *>(mxMalloc(size*sizeof(int)));
-  test_mxMalloc(NR, __LINE__, __FILE__, __func__, size*sizeof(int));
-  NonZeroElem **bc = static_cast<NonZeroElem **>(mxMalloc(size*sizeof(NonZeroElem *)));
-  test_mxMalloc(bc, __LINE__, __FILE__, __func__, size*sizeof(NonZeroElem *));
+  double* piv_v = static_cast<double*>(mxMalloc(size * sizeof(double)));
+  test_mxMalloc(piv_v, __LINE__, __FILE__, __func__, size * sizeof(double));
+  int* pivj_v = static_cast<int*>(mxMalloc(size * sizeof(int)));
+  test_mxMalloc(pivj_v, __LINE__, __FILE__, __func__, size * sizeof(int));
+  int* pivk_v = static_cast<int*>(mxMalloc(size * sizeof(int)));
+  test_mxMalloc(pivk_v, __LINE__, __FILE__, __func__, size * sizeof(int));
+  int* NR = static_cast<int*>(mxMalloc(size * sizeof(int)));
+  test_mxMalloc(NR, __LINE__, __FILE__, __func__, size * sizeof(int));
+  NonZeroElem** bc = static_cast<NonZeroElem**>(mxMalloc(size * sizeof(NonZeroElem*)));
+  test_mxMalloc(bc, __LINE__, __FILE__, __func__, size * sizeof(NonZeroElem*));
 
   for (int t = 0; t < periods; t++)
     {
 #ifdef MATLAB_MEX_FILE
       if (utIsInterruptPending())
-        throw UserException{};
+        throw UserException {};
 #endif
 
       if (record && symbolic)
         {
-          save_op = static_cast<int *>(mxMalloc(nop*sizeof(int)));
-          test_mxMalloc(save_op, __LINE__, __FILE__, __func__, nop*sizeof(int));
+          save_op = static_cast<int*>(mxMalloc(nop * sizeof(int)));
+          test_mxMalloc(save_op, __LINE__, __FILE__, __func__, nop * sizeof(int));
           nopa = nop;
         }
       nop = 0;
       Clear_u();
-      int ti = t*size;
-      for (int i = ti; i < size+ti; i++)
+      int ti = t * size;
+      for (int i = ti; i < size + ti; i++)
         {
           /*finding the max-pivot*/
           double piv = 0, piv_abs = 0;
@@ -3635,22 +3737,23 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
                         if (fabs(piv_v[j]) > 0)
                           {
                             if (markowitz_c > 0)
-                              markovitz = exp(log(fabs(piv_v[j])/piv_abs)
-                                              -markowitz_c*log(static_cast<double>(NR[j])
-                                                               /static_cast<double>(N_max)));
+                              markovitz = exp(log(fabs(piv_v[j]) / piv_abs)
+                                              - markowitz_c
+                                                    * log(static_cast<double>(NR[j])
+                                                          / static_cast<double>(N_max)));
                             else
-                              markovitz = fabs(piv_v[j])/piv_abs;
+                              markovitz = fabs(piv_v[j]) / piv_abs;
                           }
                         else
                           markovitz = 0;
                       }
                     else
-                      markovitz = fabs(piv_v[j])/piv_abs;
+                      markovitz = fabs(piv_v[j]) / piv_abs;
                     if (markovitz > markovitz_max)
                       {
                         piv = piv_v[j];
-                        pivj = pivj_v[j]; //Line number
-                        pivk = pivk_v[j]; //positi
+                        pivj = pivj_v[j]; // Line number
+                        pivk = pivk_v[j]; // positi
                         markovitz_max = markovitz;
                         NR_max = NR[j];
                       }
@@ -3663,28 +3766,31 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
                         if (fabs(piv_v[j]) > 0)
                           {
                             if (markowitz_c > 0)
-                              markovitz = exp(log(fabs(piv_v[j])/piv_abs)
-                                              -markowitz_c*log(static_cast<double>(NR[j])
-                                                               /static_cast<double>(N_max)));
+                              markovitz = exp(log(fabs(piv_v[j]) / piv_abs)
+                                              - markowitz_c
+                                                    * log(static_cast<double>(NR[j])
+                                                          / static_cast<double>(N_max)));
                             else
-                              markovitz = fabs(piv_v[j])/piv_abs;
+                              markovitz = fabs(piv_v[j]) / piv_abs;
                           }
                         else
                           markovitz = 0;
                       }
                     else
-                      markovitz = fabs(piv_v[j])/piv_abs;
+                      markovitz = fabs(piv_v[j]) / piv_abs;
                     if (NR[j] == 1)
                       {
                         piv = piv_v[j];
-                        pivj = pivj_v[j]; //Line number
-                        pivk = pivk_v[j]; //positi
+                        pivj = pivj_v[j]; // Line number
+                        pivk = pivk_v[j]; // positi
                         markovitz_max = markovitz;
                         NR_max = NR[j];
                       }
                   }
               if (fabs(piv) < eps && verbosity >= 1)
-                mexPrintf("==> Error NR_max=%d, N_max=%d and piv=%f, piv_abs=%f, markovitz_max=%f\n", NR_max, N_max, piv, piv_abs, markovitz_max);
+                mexPrintf(
+                    "==> Error NR_max=%d, N_max=%d and piv=%f, piv_abs=%f, markovitz_max=%f\n",
+                    NR_max, N_max, piv, piv_abs, markovitz_max);
               if (NR_max == 0 && verbosity >= 1)
                 mexPrintf("==> Error NR_max=0 and piv=%f, markovitz_max=%f\n", piv, markovitz_max);
               pivot[i] = pivj;
@@ -3694,7 +3800,7 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
             }
           else
             {
-              pivj = pivot[i-size]+size;
+              pivj = pivot[i - size] + size;
               pivot[i] = pivj;
               first = At_Pos(pivj, i);
               pivk = first->u_index;
@@ -3705,12 +3811,12 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
 
           if (record && symbolic)
             {
-              if (nop+1 >= nopa)
+              if (nop + 1 >= nopa)
                 {
-                  nopa = static_cast<long>(mem_increasing_factor*static_cast<double>(nopa));
-                  save_op = static_cast<int *>(mxRealloc(save_op, nopa*sizeof(int)));
+                  nopa = static_cast<long>(mem_increasing_factor * static_cast<double>(nopa));
+                  save_op = static_cast<int*>(mxRealloc(save_op, nopa * sizeof(int)));
                 }
-              t_save_op_s *save_op_s = reinterpret_cast<t_save_op_s *>(&save_op[nop]);
+              t_save_op_s* save_op_s = reinterpret_cast<t_save_op_s*>(&save_op[nop]);
               save_op_s->operat = IFLD;
               save_op_s->first = pivk;
               save_op_s->lag = 0;
@@ -3718,10 +3824,12 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
               if (piv_abs < eps)
                 {
                   if (block_num > 1)
-                    throw FatalException{"In Solve_ByteCode_Symbolic_Sparse_GaussianElimination, singular system in block "
-                                         + to_string(block_num+1)};
+                    throw FatalException {"In Solve_ByteCode_Symbolic_Sparse_GaussianElimination, "
+                                          "singular system in block "
+                                          + to_string(block_num + 1)};
                   else
-                    throw FatalException{"In Solve_ByteCode_Symbolic_Sparse_GaussianElimination, singular system"};
+                    throw FatalException {
+                        "In Solve_ByteCode_Symbolic_Sparse_GaussianElimination, singular system"};
                 }
               /*divide all the non zeros elements of the line pivj by the max_pivot*/
               int nb_var;
@@ -3729,25 +3837,25 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
               for (int j = 0; j < nb_var; j++)
                 {
                   u[first->u_index] /= piv;
-                  if (nop+j*2+1 >= nopa)
+                  if (nop + j * 2 + 1 >= nopa)
                     {
-                      nopa = static_cast<long>(mem_increasing_factor*static_cast<double>(nopa));
-                      save_op = static_cast<int *>(mxRealloc(save_op, nopa*sizeof(int)));
+                      nopa = static_cast<long>(mem_increasing_factor * static_cast<double>(nopa));
+                      save_op = static_cast<int*>(mxRealloc(save_op, nopa * sizeof(int)));
                     }
-                  save_op_s = reinterpret_cast<t_save_op_s *>(&save_op[nop+j*2]);
+                  save_op_s = reinterpret_cast<t_save_op_s*>(&save_op[nop + j * 2]);
                   save_op_s->operat = IFDIV;
                   save_op_s->first = first->u_index;
                   save_op_s->lag = first->lag_index;
                   first = first->NZE_R_N;
                 }
-              nop += nb_var*2;
+              nop += nb_var * 2;
               u[b[pivj]] /= piv;
-              if (nop+1 >= nopa)
+              if (nop + 1 >= nopa)
                 {
-                  nopa = static_cast<long>(mem_increasing_factor*static_cast<double>(nopa));
-                  save_op = static_cast<int *>(mxRealloc(save_op, nopa*sizeof(int)));
+                  nopa = static_cast<long>(mem_increasing_factor * static_cast<double>(nopa));
+                  save_op = static_cast<int*>(mxRealloc(save_op, nopa * sizeof(int)));
                 }
-              save_op_s = reinterpret_cast<t_save_op_s *>(&save_op[nop]);
+              save_op_s = reinterpret_cast<t_save_op_s*>(&save_op[nop]);
               save_op_s->operat = IFDIV;
               save_op_s->first = b[pivj];
               save_op_s->lag = 0;
@@ -3765,23 +3873,23 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
                 }
               for (int j = 0; j < nb_eq_todo; j++)
                 {
-                  t_save_op_s *save_op_s_l;
-                  NonZeroElem *first = bc[j];
+                  t_save_op_s* save_op_s_l;
+                  NonZeroElem* first = bc[j];
                   int row = first->r_index;
                   double first_elem = u[first->u_index];
-                  if (nop+1 >= nopa)
+                  if (nop + 1 >= nopa)
                     {
-                      nopa = static_cast<long>(mem_increasing_factor*static_cast<double>(nopa));
-                      save_op = static_cast<int *>(mxRealloc(save_op, nopa*sizeof(int)));
+                      nopa = static_cast<long>(mem_increasing_factor * static_cast<double>(nopa));
+                      save_op = static_cast<int*>(mxRealloc(save_op, nopa * sizeof(int)));
                     }
-                  save_op_s_l = reinterpret_cast<t_save_op_s *>(&save_op[nop]);
+                  save_op_s_l = reinterpret_cast<t_save_op_s*>(&save_op[nop]);
                   save_op_s_l->operat = IFLD;
                   save_op_s_l->first = first->u_index;
                   save_op_s_l->lag = abs(first->lag_index);
                   nop += 2;
 
                   int nb_var_piv = nb_var_piva;
-                  NonZeroElem *first_piv = first_piva;
+                  NonZeroElem* first_piv = first_piva;
                   auto [nb_var_sub, first_sub] = At_Row(row);
                   int l_sub = 0;
                   int l_piv = 0;
@@ -3799,22 +3907,24 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
                           if (first_sub)
                             sub_c_index = first_sub->c_index;
                           else
-                            sub_c_index = size*periods;
+                            sub_c_index = size * periods;
                           l_sub++;
                         }
                       else if (sub_c_index > piv_c_index || l_sub >= nb_var_sub)
                         {
-                          // There is an nonzero element at row pivot but not at the current row=> insert a negative element in the current row
+                          // There is an nonzero element at row pivot but not at the current row=>
+                          // insert a negative element in the current row
                           int tmp_u_count = Get_u();
-                          int lag = first_piv->c_index/size-row/size;
+                          int lag = first_piv->c_index / size - row / size;
                           Insert(row, first_piv->c_index, tmp_u_count, lag);
-                          u[tmp_u_count] = -u[first_piv->u_index]*first_elem;
-                          if (nop+2 >= nopa)
+                          u[tmp_u_count] = -u[first_piv->u_index] * first_elem;
+                          if (nop + 2 >= nopa)
                             {
-                              nopa = static_cast<long>(mem_increasing_factor*static_cast<double>(nopa));
-                              save_op = static_cast<int *>(mxRealloc(save_op, nopa*sizeof(int)));
+                              nopa = static_cast<long>(mem_increasing_factor
+                                                       * static_cast<double>(nopa));
+                              save_op = static_cast<int*>(mxRealloc(save_op, nopa * sizeof(int)));
                             }
-                          save_op_s_l = reinterpret_cast<t_save_op_s *>(&save_op[nop]);
+                          save_op_s_l = reinterpret_cast<t_save_op_s*>(&save_op[nop]);
                           save_op_s_l->operat = IFLESS;
                           save_op_s_l->first = tmp_u_count;
                           save_op_s_l->second = first_piv->u_index;
@@ -3824,39 +3934,41 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
                           if (first_piv)
                             piv_c_index = first_piv->c_index;
                           else
-                            piv_c_index = size*periods;
+                            piv_c_index = size * periods;
                           l_piv++;
                         }
                       else /*first_sub->c_index==first_piv->c_index*/
                         {
                           if (i == sub_c_index)
                             {
-                              NonZeroElem *firsta = first;
-                              NonZeroElem *first_suba = first_sub->NZE_R_N;
+                              NonZeroElem* firsta = first;
+                              NonZeroElem* first_suba = first_sub->NZE_R_N;
                               Delete(first_sub->r_index, first_sub->c_index);
                               first = firsta->NZE_C_N;
                               first_sub = first_suba;
                               if (first_sub)
                                 sub_c_index = first_sub->c_index;
                               else
-                                sub_c_index = size*periods;
+                                sub_c_index = size * periods;
                               l_sub++;
                               first_piv = first_piv->NZE_R_N;
                               if (first_piv)
                                 piv_c_index = first_piv->c_index;
                               else
-                                piv_c_index = size*periods;
+                                piv_c_index = size * periods;
                               l_piv++;
                             }
                           else
                             {
-                              u[first_sub->u_index] -= u[first_piv->u_index]*first_elem;
-                              if (nop+3 >= nopa)
+                              u[first_sub->u_index] -= u[first_piv->u_index] * first_elem;
+                              if (nop + 3 >= nopa)
                                 {
-                                  nopa = static_cast<long>(mem_increasing_factor*static_cast<double>(nopa));
-                                  save_op = static_cast<int *>(mxRealloc(save_op, nopa*sizeof(int)));
+                                  nopa = static_cast<long>(mem_increasing_factor
+                                                           * static_cast<double>(nopa));
+                                  save_op
+                                      = static_cast<int*>(mxRealloc(save_op, nopa * sizeof(int)));
                                 }
-                              save_op_s_l = reinterpret_cast<t_save_op_s *>(&save_op[nop]);
+                              save_op_s_l = reinterpret_cast<t_save_op_s*>(&save_op[nop]);
                               save_op_s_l->operat = IFSUB;
                               save_op_s_l->first = first_sub->u_index;
                               save_op_s_l->second = first_piv->u_index;
@@ -3866,25 +3978,25 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
                               if (first_sub)
                                 sub_c_index = first_sub->c_index;
                               else
-                                sub_c_index = size*periods;
+                                sub_c_index = size * periods;
                               l_sub++;
                               first_piv = first_piv->NZE_R_N;
                               if (first_piv)
                                 piv_c_index = first_piv->c_index;
                               else
-                                piv_c_index = size*periods;
+                                piv_c_index = size * periods;
                               l_piv++;
                             }
                         }
                     }
-                  u[b[row]] -= u[b[pivj]]*first_elem;
+                  u[b[row]] -= u[b[pivj]] * first_elem;
 
-                  if (nop+3 >= nopa)
+                  if (nop + 3 >= nopa)
                     {
-                      nopa = static_cast<long>(mem_increasing_factor*static_cast<double>(nopa));
-                      save_op = static_cast<int *>(mxRealloc(save_op, nopa*sizeof(int)));
+                      nopa = static_cast<long>(mem_increasing_factor * static_cast<double>(nopa));
+                      save_op = static_cast<int*>(mxRealloc(save_op, nopa * sizeof(int)));
                     }
-                  save_op_s_l = reinterpret_cast<t_save_op_s *>(&save_op[nop]);
+                  save_op_s_l = reinterpret_cast<t_save_op_s*>(&save_op[nop]);
                   save_op_s_l->operat = IFSUB;
                   save_op_s_l->first = b[row];
                   save_op_s_l->second = b[pivj];
@@ -3898,10 +4010,12 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
               if (piv_abs < eps)
                 {
                   if (block_num > 1)
-                    throw FatalException{"In Solve_ByteCode_Symbolic_Sparse_GaussianElimination, singular system in block "
-                                         + to_string(block_num+1)};
+                    throw FatalException {"In Solve_ByteCode_Symbolic_Sparse_GaussianElimination, "
+                                          "singular system in block "
+                                          + to_string(block_num + 1)};
                   else
-                    throw FatalException{"In Solve_ByteCode_Symbolic_Sparse_GaussianElimination, singular system"};
+                    throw FatalException {
+                        "In Solve_ByteCode_Symbolic_Sparse_GaussianElimination, singular system"};
                 }
               // Divide all the non zeros elements of the line pivj by the max_pivot
               int nb_var;
@@ -3911,7 +4025,7 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
                   u[first->u_index] /= piv;
                   first = first->NZE_R_N;
                 }
-              nop += nb_var*2;
+              nop += nb_var * 2;
               u[b[pivj]] /= piv;
               nop += 2;
               // Subtract the elements on the non treated lines
@@ -3927,12 +4041,12 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
                 }
               for (int j = 0; j < nb_eq_todo; j++)
                 {
-                  NonZeroElem *first = bc[j];
+                  NonZeroElem* first = bc[j];
                   int row = first->r_index;
                   double first_elem = u[first->u_index];
                   nop += 2;
                   int nb_var_piv = nb_var_piva;
-                  NonZeroElem *first_piv = first_piva;
+                  NonZeroElem* first_piv = first_piva;
                   auto [nb_var_sub, first_sub] = At_Row(row);
                   int l_sub = 0;
                   int l_piv = 0;
@@ -3949,7 +4063,7 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
                           if (first_sub)
                             sub_c_index = first_sub->c_index;
                           else
-                            sub_c_index = size*periods;
+                            sub_c_index = size * periods;
                           l_sub++;
                         }
                       else if (sub_c_index > piv_c_index || l_sub >= nb_var_sub)
@@ -3958,65 +4072,65 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
                              at the current row ⇒ insert a negative element in the
                              current row */
                           int tmp_u_count = Get_u();
-                          int lag = first_piv->c_index/size-row/size;
+                          int lag = first_piv->c_index / size - row / size;
                           Insert(row, first_piv->c_index, tmp_u_count, lag);
-                          u[tmp_u_count] = -u[first_piv->u_index]*first_elem;
+                          u[tmp_u_count] = -u[first_piv->u_index] * first_elem;
                           nop += 3;
                           first_piv = first_piv->NZE_R_N;
                           if (first_piv)
                             piv_c_index = first_piv->c_index;
                           else
-                            piv_c_index = size*periods;
+                            piv_c_index = size * periods;
                           l_piv++;
                         }
                       else /*first_sub->c_index==first_piv->c_index*/
                         {
                           if (i == sub_c_index)
                             {
-                              NonZeroElem *firsta = first;
-                              NonZeroElem *first_suba = first_sub->NZE_R_N;
+                              NonZeroElem* firsta = first;
+                              NonZeroElem* first_suba = first_sub->NZE_R_N;
                               Delete(first_sub->r_index, first_sub->c_index);
                               first = firsta->NZE_C_N;
                               first_sub = first_suba;
                               if (first_sub)
                                 sub_c_index = first_sub->c_index;
                               else
-                                sub_c_index = size*periods;
+                                sub_c_index = size * periods;
                               l_sub++;
                               first_piv = first_piv->NZE_R_N;
                               if (first_piv)
                                 piv_c_index = first_piv->c_index;
                               else
-                                piv_c_index = size*periods;
+                                piv_c_index = size * periods;
                               l_piv++;
                             }
                           else
                             {
-                              u[first_sub->u_index] -= u[first_piv->u_index]*first_elem;
+                              u[first_sub->u_index] -= u[first_piv->u_index] * first_elem;
                               nop += 3;
                               first_sub = first_sub->NZE_R_N;
                               if (first_sub)
                                 sub_c_index = first_sub->c_index;
                               else
-                                sub_c_index = size*periods;
+                                sub_c_index = size * periods;
                               l_sub++;
                               first_piv = first_piv->NZE_R_N;
                               if (first_piv)
                                 piv_c_index = first_piv->c_index;
                               else
-                                piv_c_index = size*periods;
+                                piv_c_index = size * periods;
                               l_piv++;
                             }
                         }
                     }
-                  u[b[row]] -= u[b[pivj]]*first_elem;
+                  u[b[row]] -= u[b[pivj]] * first_elem;
                   nop += 3;
                 }
             }
         }
       if (symbolic)
         {
-          if (t > static_cast<int>(periods*0.35))
+          if (t > static_cast<int>(periods * 0.35))
             {
               symbolic = false;
               mxFree(save_opaa);
@@ -4025,7 +4139,7 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
             }
           else if (record && nop == nop1)
             {
-              if (t > static_cast<int>(periods*0.35))
+              if (t > static_cast<int>(periods * 0.35))
                 {
                   symbolic = false;
                   if (save_opaa)
@@ -4102,7 +4216,7 @@ Interpreter::Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic)
     }
 
   // The backward substitution
-  for (int i = 0; i < y_size*(periods+y_kmin); i++)
+  for (int i = 0; i < y_size * (periods + y_kmin); i++)
     ya[i] = y[i];
   slowc_save = slowc;
   bksub(tbreak, last_period);
@@ -4121,7 +4235,8 @@ Interpreter::Check_and_Correct_Previous_Iteration()
           for (int i = 0; i < size; i++)
             {
               int eq = index_vara[i];
-              y[eq+it_*y_size] = ya[eq+it_*y_size] + slowc_save * direction[eq+it_*y_size];
+              y[eq + it_ * y_size]
+                  = ya[eq + it_ * y_size] + slowc_save * direction[eq + it_ * y_size];
             }
           compute_complete(true);
         }
@@ -4133,7 +4248,8 @@ Interpreter::Check_and_Correct_Previous_Iteration()
           for (int i = 0; i < size; i++)
             {
               int eq = index_vara[i];
-              y[eq+it_*y_size] = ya[eq+it_*y_size] + slowc_save * direction[eq+it_*y_size];
+              y[eq + it_ * y_size]
+                  = ya[eq + it_ * y_size] + slowc_save * direction[eq + it_ * y_size];
             }
           compute_complete(true);
         }
@@ -4142,7 +4258,7 @@ Interpreter::Check_and_Correct_Previous_Iteration()
       for (int i = 0; i < size; i++)
         {
           int eq = index_vara[i];
-          y[eq+it_*y_size] = ya[eq+it_*y_size] + slowc_save * direction[eq+it_*y_size];
+          y[eq + it_ * y_size] = ya[eq + it_ * y_size] + slowc_save * direction[eq + it_ * y_size];
         }
       compute_complete(false);
     }
@@ -4150,7 +4266,7 @@ Interpreter::Check_and_Correct_Previous_Iteration()
     for (int i = 0; i < size; i++)
       {
         int eq = index_vara[i];
-        y[eq+it_*y_size] = ya[eq+it_*y_size] + slowc_save * direction[eq+it_*y_size];
+        y[eq + it_ * y_size] = ya[eq + it_ * y_size] + slowc_save * direction[eq + it_ * y_size];
       }
   slowc_save = slowc;
 }
@@ -4181,9 +4297,13 @@ Interpreter::Simulate_One_Boundary()
                 break;
               }
           if (select)
-            mexPrintf("-> variable %s (%d) at time %d = %f direction = %f\n", get_variable(SymbolType::endogenous, j).c_str(), j+1, it_, y[j+it_*y_size], direction[j+it_*y_size]);
+            mexPrintf("-> variable %s (%d) at time %d = %f direction = %f\n",
+                      get_variable(SymbolType::endogenous, j).c_str(), j + 1, it_,
+                      y[j + it_ * y_size], direction[j + it_ * y_size]);
           else
-            mexPrintf("   variable %s (%d) at time %d = %f direction = %f\n", get_variable(SymbolType::endogenous, j).c_str(), j+1, it_, y[j+it_*y_size], direction[j+it_*y_size]);
+            mexPrintf("   variable %s (%d) at time %d = %f direction = %f\n",
+                      get_variable(SymbolType::endogenous, j).c_str(), j + 1, it_,
+                      y[j + it_ * y_size], direction[j + it_ * y_size]);
         }
 #endif
       if (steady_state)
@@ -4191,20 +4311,25 @@ Interpreter::Simulate_One_Boundary()
           if (verbosity >= 1)
             {
               if (iter == 0)
-                mexPrintf(" the initial values of endogenous variables are too far from the solution.\nChange them!\n");
+                mexPrintf(" the initial values of endogenous variables are too far from the "
+                          "solution.\nChange them!\n");
               else
-                mexPrintf(" dynare cannot improve the simulation in block %d at time %d (variable %d)\n", block_num+1, it_+1, index_vara[max_res_idx]+1);
+                mexPrintf(
+                    " dynare cannot improve the simulation in block %d at time %d (variable %d)\n",
+                    block_num + 1, it_ + 1, index_vara[max_res_idx] + 1);
               mexEvalString("drawnow;");
             }
         }
       else
         {
           if (iter == 0)
-            throw FatalException{"In Simulate_One_Boundary, The initial values of endogenous variables are too far from the solution. Change them!"};
+            throw FatalException {"In Simulate_One_Boundary, The initial values of endogenous "
+                                  "variables are too far from the solution. Change them!"};
           else
-            throw FatalException{"In Simulate_One_Boundary, Dynare cannot improve the simulation in block "
-                                 + to_string(block_num+1) + " at time " + to_string(it_+1)
-                                 + " (variable " + to_string(index_vara[max_res_idx]+1)};
+            throw FatalException {
+                "In Simulate_One_Boundary, Dynare cannot improve the simulation in block "
+                + to_string(block_num + 1) + " at time " + to_string(it_ + 1) + " (variable "
+                + to_string(index_vara[max_res_idx] + 1)};
         }
     }
 
@@ -4221,16 +4346,20 @@ Interpreter::Simulate_One_Boundary()
               mexPrintf("MODEL STEADY STATE: (method=Sparse LU)\n");
               break;
             case 7:
-              mexPrintf(preconditioner_print_out("MODEL STEADY STATE: (method=GMRES)\n", preconditioner, true).c_str());
+              mexPrintf(preconditioner_print_out("MODEL STEADY STATE: (method=GMRES)\n",
+                                                 preconditioner, true)
+                            .c_str());
               break;
             case 8:
-              mexPrintf(preconditioner_print_out("MODEL STEADY STATE: (method=BiCGStab)\n", preconditioner, true).c_str());
+              mexPrintf(preconditioner_print_out("MODEL STEADY STATE: (method=BiCGStab)\n",
+                                                 preconditioner, true)
+                            .c_str());
               break;
             }
         }
 
       mexPrintf("------------------------------------\n");
-      mexPrintf("      Iteration no. %d\n", iter+1);
+      mexPrintf("      Iteration no. %d\n", iter + 1);
       mexPrintf("      Inf-norm error = %.3e\n", static_cast<double>(max_res));
       mexPrintf("      2-norm error   = %.3e\n", static_cast<double>(sqrt(res2)));
       mexPrintf("      1-norm error   = %.3e\n", static_cast<double>(res1));
@@ -4244,17 +4373,19 @@ Interpreter::Simulate_One_Boundary()
     {
       x0_m = mxCreateDoubleMatrix(size, 1, mxREAL);
       if (!x0_m)
-        throw FatalException{"In Simulate_One_Boundary, can't allocate x0_m vector"};
+        throw FatalException {"In Simulate_One_Boundary, can't allocate x0_m vector"};
       if (!((solve_algo == 6 && steady_state)
             || ((stack_solve_algo == 0 || stack_solve_algo == 1 || stack_solve_algo == 4
-                 || stack_solve_algo == 6) && !steady_state)))
+                 || stack_solve_algo == 6)
+                && !steady_state)))
         {
           b_m = mxCreateDoubleMatrix(size, 1, mxREAL);
           if (!b_m)
-            throw FatalException{"In Simulate_One_Boundary, can't allocate b_m vector"};
-          A_m = mxCreateSparse(size, size, min(static_cast<int>(IM_i.size()*2), size * size), mxREAL);
+            throw FatalException {"In Simulate_One_Boundary, can't allocate b_m vector"};
+          A_m = mxCreateSparse(size, size, min(static_cast<int>(IM_i.size() * 2), size * size),
+                               mxREAL);
           if (!A_m)
-            throw FatalException{"In Simulate_One_Boundary, can't allocate A_m matrix"};
+            throw FatalException {"In Simulate_One_Boundary, can't allocate A_m matrix"};
           zero_solution = Init_Matlab_Sparse_One_Boundary(A_m, b_m, x0_m);
         }
       else
@@ -4264,9 +4395,11 @@ Interpreter::Simulate_One_Boundary()
             {
               mxFree(Ai_save);
               mxFree(Ax_save);
-              Ai_save = static_cast<SuiteSparse_long *>(mxMalloc(Ap[size] * sizeof(SuiteSparse_long)));
-              test_mxMalloc(Ai_save, __LINE__, __FILE__, __func__, Ap[size] * sizeof(SuiteSparse_long));
-              Ax_save = static_cast<double *>(mxMalloc(Ap[size] * sizeof(double)));
+              Ai_save
+                  = static_cast<SuiteSparse_long*>(mxMalloc(Ap[size] * sizeof(SuiteSparse_long)));
+              test_mxMalloc(Ai_save, __LINE__, __FILE__, __func__,
+                            Ap[size] * sizeof(SuiteSparse_long));
+              Ax_save = static_cast<double*>(mxMalloc(Ap[size] * sizeof(double)));
               test_mxMalloc(Ax_save, __LINE__, __FILE__, __func__, Ap[size] * sizeof(double));
             }
           copy_n(Ap, size + 1, Ap_save);
@@ -4279,9 +4412,9 @@ Interpreter::Simulate_One_Boundary()
     for (int i = 0; i < size; i++)
       {
         int eq = index_vara[i];
-        double yy = -(y[eq+it_*y_size]);
+        double yy = -(y[eq + it_ * y_size]);
         direction[eq] = yy;
-        y[eq+it_*y_size] += slowc * yy;
+        y[eq + it_ * y_size] += slowc * yy;
       }
   else
     {
@@ -4291,7 +4424,10 @@ Interpreter::Simulate_One_Boundary()
         Solve_Matlab_GMRES(A_m, b_m, false, x0_m);
       else if ((solve_algo == 8 && steady_state) || (stack_solve_algo == 3 && !steady_state))
         Solve_Matlab_BiCGStab(A_m, b_m, false, x0_m, preconditioner);
-      else if ((solve_algo == 6 && steady_state) || ((stack_solve_algo == 0 || stack_solve_algo == 1 || stack_solve_algo == 4 || stack_solve_algo == 6) && !steady_state))
+      else if ((solve_algo == 6 && steady_state)
+               || ((stack_solve_algo == 0 || stack_solve_algo == 1 || stack_solve_algo == 4
+                    || stack_solve_algo == 6)
+                   && !steady_state))
         {
           Solve_LU_UMFPack_One_Boundary(Ap, Ai, Ax, b);
           mxDestroyArray(x0_m);
@@ -4333,35 +4469,38 @@ Interpreter::solve_non_linear()
   if (!cvg)
     {
       if (steady_state)
-        throw FatalException{"In Solve Forward/Backward Complete, convergence not achieved in block "
-                             + to_string(block_num+1) + ", after " + to_string(iter)
-                             + " iterations"};
+        throw FatalException {
+            "In Solve Forward/Backward Complete, convergence not achieved in block "
+            + to_string(block_num + 1) + ", after " + to_string(iter) + " iterations"};
       else
-        throw FatalException{"In Solve Forward/Backward Complete, convergence not achieved in block "
-                             + to_string(block_num+1) + ", at time " + to_string(it_)
-                             + ", after " + to_string(iter) + " iterations"};
+        throw FatalException {
+            "In Solve Forward/Backward Complete, convergence not achieved in block "
+            + to_string(block_num + 1) + ", at time " + to_string(it_) + ", after "
+            + to_string(iter) + " iterations"};
     }
 }
 
 void
 Interpreter::Simulate_Newton_One_Boundary(bool forward)
 {
-  g1 = static_cast<double *>(mxMalloc(size*size*sizeof(double)));
-  test_mxMalloc(g1, __LINE__, __FILE__, __func__, size*size*sizeof(double));
-  r = static_cast<double *>(mxMalloc(size*sizeof(double)));
-  test_mxMalloc(r, __LINE__, __FILE__, __func__, size*sizeof(double));
+  g1 = static_cast<double*>(mxMalloc(size * size * sizeof(double)));
+  test_mxMalloc(g1, __LINE__, __FILE__, __func__, size * size * sizeof(double));
+  r = static_cast<double*>(mxMalloc(size * sizeof(double)));
+  test_mxMalloc(r, __LINE__, __FILE__, __func__, size * sizeof(double));
   iter = 0;
   if ((solve_algo == 6 && steady_state)
-      || ((stack_solve_algo == 0 || stack_solve_algo == 1 || stack_solve_algo == 4 || stack_solve_algo == 6) && !steady_state))
+      || ((stack_solve_algo == 0 || stack_solve_algo == 1 || stack_solve_algo == 4
+           || stack_solve_algo == 6)
+          && !steady_state))
     {
-      Ap_save = static_cast<SuiteSparse_long *>(mxMalloc((size + 1) * sizeof(SuiteSparse_long)));
+      Ap_save = static_cast<SuiteSparse_long*>(mxMalloc((size + 1) * sizeof(SuiteSparse_long)));
       test_mxMalloc(Ap_save, __LINE__, __FILE__, __func__, (size + 1) * sizeof(SuiteSparse_long));
       Ap_save[size] = 0;
-      Ai_save = static_cast<SuiteSparse_long *>(mxMalloc(1 * sizeof(SuiteSparse_long)));
+      Ai_save = static_cast<SuiteSparse_long*>(mxMalloc(1 * sizeof(SuiteSparse_long)));
       test_mxMalloc(Ai_save, __LINE__, __FILE__, __func__, 1 * sizeof(SuiteSparse_long));
-      Ax_save = static_cast<double *>(mxMalloc(1 * sizeof(double)));
+      Ax_save = static_cast<double*>(mxMalloc(1 * sizeof(double)));
       test_mxMalloc(Ax_save, __LINE__, __FILE__, __func__, 1 * sizeof(double));
-      b_save = static_cast<double *>(mxMalloc((size) * sizeof(SuiteSparse_long)));
+      b_save = static_cast<double*>(mxMalloc((size) * sizeof(SuiteSparse_long)));
       test_mxMalloc(b_save, __LINE__, __FILE__, __func__, (size) * sizeof(SuiteSparse_long));
     }
   if (steady_state)
@@ -4375,23 +4514,25 @@ Interpreter::Simulate_Newton_One_Boundary(bool forward)
   else if (forward)
     {
       if (!is_linear)
-        for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
+        for (it_ = y_kmin; it_ < periods + y_kmin; it_++)
           solve_non_linear();
       else
-        for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
+        for (it_ = y_kmin; it_ < periods + y_kmin; it_++)
           solve_linear(false);
     }
   else
     {
       if (!is_linear)
-        for (it_ = periods+y_kmin-1; it_ >= y_kmin; it_--)
+        for (it_ = periods + y_kmin - 1; it_ >= y_kmin; it_--)
           solve_non_linear();
       else
-        for (it_ = periods+y_kmin-1; it_ >= y_kmin; it_--)
+        for (it_ = periods + y_kmin - 1; it_ >= y_kmin; it_--)
           solve_linear(false);
     }
   if ((solve_algo == 6 && steady_state)
-      || ((stack_solve_algo == 0 || stack_solve_algo == 1 || stack_solve_algo == 4 || stack_solve_algo == 6) && !steady_state))
+      || ((stack_solve_algo == 0 || stack_solve_algo == 1 || stack_solve_algo == 4
+           || stack_solve_algo == 6)
+          && !steady_state))
     {
       mxFree(Ap_save);
       mxFree(Ai_save);
@@ -4433,7 +4574,8 @@ Interpreter::preconditioner_print_out(string s, int preconditioner, bool ss)
 }
 
 void
-Interpreter::Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditional_local_type &vector_table_conditional_local)
+Interpreter::Simulate_Newton_Two_Boundaries(
+    bool cvg, const vector_table_conditional_local_type& vector_table_conditional_local)
 {
   double top = 0.5;
   double bottom = 0.1;
@@ -4441,7 +4583,7 @@ Interpreter::Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditi
   if (start_compare == 0)
     start_compare = y_kmin;
   u_count_alloc_save = u_count_alloc;
-  auto t1 { chrono::high_resolution_clock::now() };
+  auto t1 {chrono::high_resolution_clock::now()};
   nop1 = 0;
   mxArray *b_m = nullptr, *A_m = nullptr, *x0_m = nullptr;
   double *Ax {nullptr}, *b {nullptr};
@@ -4450,7 +4592,7 @@ Interpreter::Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditi
   assert(stack_solve_algo == 0 || stack_solve_algo == 2 || stack_solve_algo == 3
          || stack_solve_algo == 4 || stack_solve_algo == 5);
 
-  if (isnan(res1) || isinf(res1) || (res2 > 12*g0 && iter > 0))
+  if (isnan(res1) || isinf(res1) || (res2 > 12 * g0 && iter > 0))
     {
       if (iter == 0 || fabs(slowc_save) < 1e-8)
         {
@@ -4468,18 +4610,24 @@ Interpreter::Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditi
               if (verbosity >= 2)
                 {
                   if (select)
-                    mexPrintf("-> variable %s (%d) at time %d = %f direction = %f\n", symbol_table.getName(SymbolType::endogenous, j).c_str(), j+1, it_, y[j+it_*y_size], direction[j+it_*y_size]);
+                    mexPrintf("-> variable %s (%d) at time %d = %f direction = %f\n",
+                              symbol_table.getName(SymbolType::endogenous, j).c_str(), j + 1, it_,
+                              y[j + it_ * y_size], direction[j + it_ * y_size]);
                   else
-                    mexPrintf("   variable %s (%d) at time %d = %f direction = %f\n", symbol_table.getName(SymbolType::endogenous, j).c_str(), j+1, it_, y[j+it_*y_size], direction[j+it_*y_size]);
+                    mexPrintf("   variable %s (%d) at time %d = %f direction = %f\n",
+                              symbol_table.getName(SymbolType::endogenous, j).c_str(), j + 1, it_,
+                              y[j + it_ * y_size], direction[j + it_ * y_size]);
                 }
             }
           if (iter == 0)
-            throw FatalException{"In Simulate_Newton_Two_Boundaries, the initial values of endogenous variables are too far from the solution. Change them!"};
+            throw FatalException {
+                "In Simulate_Newton_Two_Boundaries, the initial values of endogenous variables are "
+                "too far from the solution. Change them!"};
           else
-            throw FatalException{"In Simulate_Newton_Two_Boundaries, dynare cannot improve the simulation in block "
-                                 + to_string(block_num+1) + " at time " + to_string(it_+1)
-                                 + " (variable " + to_string(index_vara[max_res_idx]+1)
-                                 + " = " + to_string(max_res) + ")"};
+            throw FatalException {
+                "In Simulate_Newton_Two_Boundaries, dynare cannot improve the simulation in block "
+                + to_string(block_num + 1) + " at time " + to_string(it_ + 1) + " (variable "
+                + to_string(index_vara[max_res_idx] + 1) + " = " + to_string(max_res) + ")"};
         }
       if (!(isnan(res1) || isinf(res1)) && !(isnan(g0) || isinf(g0))
           && (stack_solve_algo == 4 || stack_solve_algo == 5))
@@ -4493,22 +4641,22 @@ Interpreter::Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditi
             {
               double t1 = res2 - gp0 * slowc_save - g0;
               double t2 = glambda2 - gp0 * prev_slowc_save - g0;
-              double a = (1/(slowc_save * slowc_save) * t1
-                          - 1/(prev_slowc_save * prev_slowc_save) * t2)
-                / (slowc_save - prev_slowc_save);
-              double b = (-prev_slowc_save/(slowc_save * slowc_save) * t1
-                          + slowc_save/(prev_slowc_save * prev_slowc_save) * t2)
-                / (slowc_save - prev_slowc_save);
+              double a = (1 / (slowc_save * slowc_save) * t1
+                          - 1 / (prev_slowc_save * prev_slowc_save) * t2)
+                         / (slowc_save - prev_slowc_save);
+              double b = (-prev_slowc_save / (slowc_save * slowc_save) * t1
+                          + slowc_save / (prev_slowc_save * prev_slowc_save) * t2)
+                         / (slowc_save - prev_slowc_save);
               prev_slowc_save = slowc_save;
-              slowc_save = max(min(-b + sqrt(b*b - 3 * a * gp0) / (3 * a),
-                                   top * slowc_save), bottom * slowc_save);
+              slowc_save = max(min(-b + sqrt(b * b - 3 * a * gp0) / (3 * a), top * slowc_save),
+                               bottom * slowc_save);
             }
           glambda2 = res2;
           try_at_iteration++;
           if (slowc_save <= bottom)
             {
-              for (int i = 0; i < y_size*(periods+y_kmin); i++)
-                y[i] = ya[i]+direction[i];
+              for (int i = 0; i < y_size * (periods + y_kmin); i++)
+                y[i] = ya[i] + direction[i];
               g0 = res2;
               gp0 = -res2;
               try_at_iteration = 0;
@@ -4524,12 +4672,13 @@ Interpreter::Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditi
       if (verbosity >= 2)
         {
           if (isnan(res1) || isinf(res1))
-            mexPrintf("The model cannot be evaluated, trying to correct it using slowc=%f\n", slowc_save);
+            mexPrintf("The model cannot be evaluated, trying to correct it using slowc=%f\n",
+                      slowc_save);
           else
             mexPrintf("Simulation diverging, trying to correct it using slowc=%f\n", slowc_save);
         }
-      for (int i = 0; i < y_size*(periods+y_kmin); i++)
-        y[i] = ya[i]+slowc_save*direction[i];
+      for (int i = 0; i < y_size * (periods + y_kmin); i++)
+        y[i] = ya[i] + slowc_save * direction[i];
       iter--;
       return;
     }
@@ -4545,12 +4694,13 @@ Interpreter::Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditi
           markowitz_c = markowitz_c_s;
           alt_symbolic_count++;
         }
-      if (res1/res1a-1 > -0.3 && symbolic && iter > 0)
+      if (res1 / res1a - 1 > -0.3 && symbolic && iter > 0)
         {
           if (restart > 2)
             {
               if (verbosity >= 2)
-                mexPrintf("Divergence or slowdown occurred during simulation.\nIn the next iteration, pivoting method will be applied to all periods.\n");
+                mexPrintf("Divergence or slowdown occurred during simulation.\nIn the next "
+                          "iteration, pivoting method will be applied to all periods.\n");
               symbolic = false;
               alt_symbolic = true;
               markowitz_c_s = markowitz_c;
@@ -4559,7 +4709,8 @@ Interpreter::Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditi
           else
             {
               if (verbosity >= 2)
-                mexPrintf("Divergence or slowdown occurred during simulation.\nIn the next iteration, pivoting method will be applied for a longer period.\n");
+                mexPrintf("Divergence or slowdown occurred during simulation.\nIn the next "
+                          "iteration, pivoting method will be applied for a longer period.\n");
               start_compare = min(tbreak_g, periods);
               restart++;
             }
@@ -4581,10 +4732,14 @@ Interpreter::Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditi
               mexPrintf("MODEL SIMULATION: (method=Sparse LU)\n");
               break;
             case 2:
-              mexPrintf(preconditioner_print_out("MODEL SIMULATION: (method=GMRES)\n", preconditioner, false).c_str());
+              mexPrintf(preconditioner_print_out("MODEL SIMULATION: (method=GMRES)\n",
+                                                 preconditioner, false)
+                            .c_str());
               break;
             case 3:
-              mexPrintf(preconditioner_print_out("MODEL SIMULATION: (method=BiCGStab)\n", preconditioner, false).c_str());
+              mexPrintf(preconditioner_print_out("MODEL SIMULATION: (method=BiCGStab)\n",
+                                                 preconditioner, false)
+                            .c_str());
               break;
             case 4:
               mexPrintf("MODEL SIMULATION: (method=Sparse LU & optimal path length)\n");
@@ -4595,7 +4750,7 @@ Interpreter::Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditi
             }
         }
       mexPrintf("------------------------------------\n");
-      mexPrintf("      Iteration no. %d\n", iter+1);
+      mexPrintf("      Iteration no. %d\n", iter + 1);
       mexPrintf("      Inf-norm error = %.3e\n", static_cast<double>(max_res));
       mexPrintf("      2-norm error   = %.3e\n", static_cast<double>(sqrt(res2)));
       mexPrintf("      1-norm error   = %.3e\n", static_cast<double>(res1));
@@ -4610,21 +4765,25 @@ Interpreter::Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditi
         Init_Gaussian_Elimination();
       else
         {
-          x0_m = mxCreateDoubleMatrix(periods*size, 1, mxREAL);
+          x0_m = mxCreateDoubleMatrix(periods * size, 1, mxREAL);
           if (!x0_m)
-            throw FatalException{"In Simulate_Newton_Two_Boundaries, can't allocate x0_m vector"};
+            throw FatalException {"In Simulate_Newton_Two_Boundaries, can't allocate x0_m vector"};
           if (stack_solve_algo == 0 || stack_solve_algo == 4)
-            tie(Ap, Ai, Ax, b) = Init_UMFPACK_Sparse_Two_Boundaries(x0_m, vector_table_conditional_local);
+            tie(Ap, Ai, Ax, b)
+                = Init_UMFPACK_Sparse_Two_Boundaries(x0_m, vector_table_conditional_local);
           else
             {
-              b_m = mxCreateDoubleMatrix(periods*size, 1, mxREAL);
+              b_m = mxCreateDoubleMatrix(periods * size, 1, mxREAL);
               if (!b_m)
-                throw FatalException{"In Simulate_Newton_Two_Boundaries, can't allocate b_m vector"};
+                throw FatalException {
+                    "In Simulate_Newton_Two_Boundaries, can't allocate b_m vector"};
               if (stack_solve_algo != 0 && stack_solve_algo != 4)
                 {
-                  A_m = mxCreateSparse(periods*size, periods*size, IM_i.size()* periods*2, mxREAL);
+                  A_m = mxCreateSparse(periods * size, periods * size, IM_i.size() * periods * 2,
+                                       mxREAL);
                   if (!A_m)
-                    throw FatalException{"In Simulate_Newton_Two_Boundaries, can't allocate A_m matrix"};
+                    throw FatalException {
+                        "In Simulate_Newton_Two_Boundaries, can't allocate A_m matrix"};
                 }
               Init_Matlab_Sparse_Two_Boundaries(A_m, b_m, x0_m);
             }
@@ -4642,10 +4801,10 @@ Interpreter::Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditi
         Solve_ByteCode_Symbolic_Sparse_GaussianElimination(symbolic);
     }
   using FloatSeconds = chrono::duration<double, chrono::seconds::period>;
-  auto t2 { chrono::high_resolution_clock::now() };
+  auto t2 {chrono::high_resolution_clock::now()};
   if (verbosity >= 1)
     {
-      mexPrintf("(** %.2f seconds **)\n", FloatSeconds{t2 - t1}.count());
+      mexPrintf("(** %.2f seconds **)\n", FloatSeconds {t2 - t1}.count());
       mexEvalString("drawnow;");
     }
   if (!steady_state && stack_solve_algo == 4)
@@ -4661,8 +4820,8 @@ Interpreter::Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditi
       slowc = xmin;
       if (verbosity >= 1)
         {
-          auto t3 { chrono::high_resolution_clock::now() };
-          mexPrintf("(** %.2f seconds **)\n", FloatSeconds{t3 - t2}.count());
+          auto t3 {chrono::high_resolution_clock::now()};
+          mexPrintf("(** %.2f seconds **)\n", FloatSeconds {t3 - t2}.count());
           mexEvalString("drawnow;");
         }
     }
@@ -4674,12 +4833,12 @@ void
 Interpreter::fixe_u()
 {
   u_count = u_count_int * periods;
-  u_count_alloc = 2*u_count;
+  u_count_alloc = 2 * u_count;
 #ifdef DEBUG
   mexPrintf("fixe_u : alloc(%d double)\n", u_count_alloc);
 #endif
-  u = static_cast<double *>(mxMalloc(u_count_alloc*sizeof(double)));
-  test_mxMalloc(u, __LINE__, __FILE__, __func__, u_count_alloc*sizeof(double));
+  u = static_cast<double*>(mxMalloc(u_count_alloc * sizeof(double)));
+  test_mxMalloc(u, __LINE__, __FILE__, __func__, u_count_alloc * sizeof(double));
 #ifdef DEBUG
   mexPrintf("u=%d\n", u);
 #endif
diff --git a/mex/sources/bytecode/Interpreter.hh b/mex/sources/bytecode/Interpreter.hh
index ef2e4e5fc1404b80672f09b01c6c024a33528b98..1a59c7535d9dc26ccdef60c6ca0c17cbabecd824 100644
--- a/mex/sources/bytecode/Interpreter.hh
+++ b/mex/sources/bytecode/Interpreter.hh
@@ -20,21 +20,21 @@
 #ifndef _INTERPRETER_HH
 #define _INTERPRETER_HH
 
-#include <vector>
-#include <string>
 #include <cstddef>
-#include <utility>
+#include <fstream>
 #include <map>
-#include <tuple>
 #include <stack>
-#include <fstream>
+#include <string>
+#include <tuple>
+#include <utility>
+#include <vector>
 
-#include "dynumfpack.h"
 #include "dynmex.h"
+#include "dynumfpack.h"
 
 #include "ErrorHandling.hh"
-#include "Mem_Mngr.hh"
 #include "Evaluate.hh"
+#include "Mem_Mngr.hh"
 
 using namespace std;
 
@@ -61,7 +61,8 @@ struct table_conditional_local_type
 using vector_table_conditional_local_type = vector<table_conditional_local_type>;
 using table_conditional_global_type = map<int, vector_table_conditional_local_type>;
 
-constexpr int IFLD = 0, IFDIV = 1, IFLESS = 2, IFSUB = 3, IFLDZ = 4, IFMUL = 5, IFSTP = 6, IFADD = 7;
+constexpr int IFLD = 0, IFDIV = 1, IFLESS = 2, IFSUB = 3, IFLDZ = 4, IFMUL = 5, IFSTP = 6,
+              IFADD = 7;
 constexpr double eps = 1e-15, very_big = 1e24;
 constexpr int alt_symbolic_count_max = 1;
 constexpr double mem_increasing_factor = 1.1;
@@ -76,13 +77,13 @@ private:
 
   void *Symbolic {nullptr}, *Numeric {nullptr};
 
-  const BasicSymbolTable &symbol_table;
+  const BasicSymbolTable& symbol_table;
   const bool steady_state; // Whether this is a static or dynamic model
 
   // Whether to use the block-decomposed version of the bytecode file
   bool block_decomposed;
 
-  Evaluate &evaluator;
+  Evaluate& evaluator;
 
   fstream SaveCode;
 
@@ -94,8 +95,8 @@ private:
 
   int *pivot, *pivotk, *pivot_save;
   double *pivotv, *pivotva;
-  int *b;
-  bool *line_done;
+  int* b;
+  bool* line_done;
   bool symbolic, alt_symbolic;
   int alt_symbolic_count;
   double markowitz_c_s;
@@ -104,7 +105,7 @@ private:
   map<tuple<int, int, int>, int> IM_i;
   int u_count_alloc, u_count_alloc_save;
   double slowc, slowc_save, prev_slowc_save, markowitz_c;
-  int *index_equa; // Actually unused
+  int* index_equa; // Actually unused
   int u_count, tbreak_g;
   int iter;
   int start_compare;
@@ -118,24 +119,24 @@ private:
   int minimal_solving_periods;
   int Per_u_, Per_y_;
   int maxit_;
-  double *direction;
+  double* direction;
   double solve_tolf;
   // 1-norm error, square of 2-norm error, ∞-norm error
   double res1, res2, max_res;
   int max_res_idx;
-  int *index_vara;
+  int* index_vara;
 
   double *y, *ya;
   int y_size;
-  double *T;
+  double* T;
   int nb_row_x;
   int y_kmin, y_kmax, periods;
   double *x, *params;
-  double *u;
-  double *steady_y;
+  double* u;
+  double* steady_y;
   double *g1, *r, *res;
-  vector<mxArray *> jacobian_block, jacobian_exo_block, jacobian_det_exo_block;
-  mxArray *GlobalTemporaryTerms;
+  vector<mxArray*> jacobian_block, jacobian_exo_block, jacobian_det_exo_block;
+  mxArray* GlobalTemporaryTerms;
   int it_;
   map<int, double> TEF;
   map<pair<int, int>, double> TEFD;
@@ -143,7 +144,7 @@ private:
 
   // Information about the current block
   int block_num; // Index of the current block
-  int size; // Size of the current block
+  int size;      // Size of the current block
   BlockSimulationType type;
   bool is_linear;
   int u_count_int;
@@ -160,47 +161,61 @@ private:
   void solve_simple_one_periods();
   void solve_simple_over_periods(bool forward);
   void compute_complete_2b();
-  void evaluate_a_block(bool initialization, bool single_block, const string &bin_base_name);
-  int simulate_a_block(const vector_table_conditional_local_type &vector_table_conditional_local, bool single_block, const string &bin_base_name);
+  void evaluate_a_block(bool initialization, bool single_block, const string& bin_base_name);
+  int simulate_a_block(const vector_table_conditional_local_type& vector_table_conditional_local,
+                       bool single_block, const string& bin_base_name);
   static string elastic(string str, unsigned int len, bool left);
-  void check_for_controlled_exo_validity(const vector<s_plan> &sconstrained_extended_path);
-  pair<bool, vector<int>> MainLoop(const string &bin_basename, bool evaluate, int block, bool constrained, const vector<s_plan> &sconstrained_extended_path, const vector_table_conditional_local_type &vector_table_conditional_local);
-  void Simulate_Newton_Two_Boundaries(bool cvg, const vector_table_conditional_local_type &vector_table_conditional_local);
+  void check_for_controlled_exo_validity(const vector<s_plan>& sconstrained_extended_path);
+  pair<bool, vector<int>>
+  MainLoop(const string& bin_basename, bool evaluate, int block, bool constrained,
+           const vector<s_plan>& sconstrained_extended_path,
+           const vector_table_conditional_local_type& vector_table_conditional_local);
+  void Simulate_Newton_Two_Boundaries(
+      bool cvg, const vector_table_conditional_local_type& vector_table_conditional_local);
   void Simulate_Newton_One_Boundary(bool forward);
   void fixe_u();
-  void Read_SparseMatrix(const string &file_name, bool two_boundaries);
+  void Read_SparseMatrix(const string& file_name, bool two_boundaries);
   void Singular_display();
   void End_Solver();
-  static int find_exo_num(const vector<s_plan> &sconstrained_extended_path, int value);
-  static int find_int_date(const vector<pair<int, double>> &per_value, int value);
+  static int find_exo_num(const vector<s_plan>& sconstrained_extended_path, int value);
+  static int find_int_date(const vector<pair<int, double>>& per_value, int value);
   void Init_Gaussian_Elimination();
-  void Init_Matlab_Sparse_Two_Boundaries(const mxArray *A_m, const mxArray *b_m, const mxArray *x0_m) const;
-  tuple<SuiteSparse_long *, SuiteSparse_long *, double *, double *> Init_UMFPACK_Sparse_Two_Boundaries(const mxArray *x0_m, const vector_table_conditional_local_type &vector_table_conditional_local) const;
-  bool Init_Matlab_Sparse_One_Boundary(const mxArray *A_m, const mxArray *b_m, const mxArray *x0_m) const;
-  tuple<bool, SuiteSparse_long *, SuiteSparse_long *, double *, double *> Init_UMFPACK_Sparse_One_Boundary(const mxArray *x0_m) const;
+  void Init_Matlab_Sparse_Two_Boundaries(const mxArray* A_m, const mxArray* b_m,
+                                         const mxArray* x0_m) const;
+  tuple<SuiteSparse_long*, SuiteSparse_long*, double*, double*> Init_UMFPACK_Sparse_Two_Boundaries(
+      const mxArray* x0_m,
+      const vector_table_conditional_local_type& vector_table_conditional_local) const;
+  bool Init_Matlab_Sparse_One_Boundary(const mxArray* A_m, const mxArray* b_m,
+                                       const mxArray* x0_m) const;
+  tuple<bool, SuiteSparse_long*, SuiteSparse_long*, double*, double*>
+  Init_UMFPACK_Sparse_One_Boundary(const mxArray* x0_m) const;
   bool Simple_Init();
   void End_Gaussian_Elimination();
-  tuple<bool, double, double, double, double> mnbrak(double &ax, double &bx);
+  tuple<bool, double, double, double, double> mnbrak(double& ax, double& bx);
   pair<bool, double> golden(double ax, double bx, double cx, double tol);
   void Solve_ByteCode_Symbolic_Sparse_GaussianElimination(bool symbolic);
   bool Solve_ByteCode_Sparse_GaussianElimination();
-  void Solve_LU_UMFPack_Two_Boundaries(SuiteSparse_long *Ap, SuiteSparse_long *Ai, double *Ax, double *b, const vector_table_conditional_local_type &vector_table_conditional_local);
-  void Solve_LU_UMFPack_One_Boundary(SuiteSparse_long *Ap, SuiteSparse_long *Ai, double *Ax, double *b);
-
-  void Solve_Matlab_GMRES(mxArray *A_m, mxArray *b_m, bool is_two_boundaries, mxArray *x0_m);
-  void Solve_Matlab_BiCGStab(mxArray *A_m, mxArray *b_m, bool is_two_boundaries, mxArray *x0_m, int precond);
+  void Solve_LU_UMFPack_Two_Boundaries(
+      SuiteSparse_long* Ap, SuiteSparse_long* Ai, double* Ax, double* b,
+      const vector_table_conditional_local_type& vector_table_conditional_local);
+  void Solve_LU_UMFPack_One_Boundary(SuiteSparse_long* Ap, SuiteSparse_long* Ai, double* Ax,
+                                     double* b);
+
+  void Solve_Matlab_GMRES(mxArray* A_m, mxArray* b_m, bool is_two_boundaries, mxArray* x0_m);
+  void Solve_Matlab_BiCGStab(mxArray* A_m, mxArray* b_m, bool is_two_boundaries, mxArray* x0_m,
+                             int precond);
   void Check_and_Correct_Previous_Iteration();
   bool Simulate_One_Boundary();
   bool solve_linear(bool do_check_and_correct);
   void solve_non_linear();
   string preconditioner_print_out(string s, int preconditioner, bool ss);
-  bool compare(int *save_op, int *save_opa, int *save_opaa, int beg_t, long nop4);
+  bool compare(int* save_op, int* save_opa, int* save_opaa, int beg_t, long nop4);
   void Insert(int r, int c, int u_index, int lag_index);
   void Delete(int r, int c);
-  pair<int, NonZeroElem *> At_Row(int r) const;
-  NonZeroElem *At_Pos(int r, int c) const;
-  pair<int, NonZeroElem *> At_Col(int c) const;
-  pair<int, NonZeroElem *> At_Col(int c, int lag) const;
+  pair<int, NonZeroElem*> At_Row(int r) const;
+  NonZeroElem* At_Pos(int r, int c) const;
+  pair<int, NonZeroElem*> At_Col(int c) const;
+  pair<int, NonZeroElem*> At_Col(int c, int lag) const;
   int NRow(int r) const;
   int NCol(int c) const;
   int Get_u();
@@ -211,17 +226,17 @@ private:
   void bksub(int tbreak, int last_period);
   void simple_bksub();
   // Computes Aᵀ where A is are sparse. The result is sparse.
-  static mxArray *Sparse_transpose(const mxArray *A_m);
+  static mxArray* Sparse_transpose(const mxArray* A_m);
   // Computes Aᵀ·B where A and B are sparse. The result is sparse.
-  static mxArray *Sparse_mult_SAT_SB(const mxArray *A_m, const mxArray *B_m);
+  static mxArray* Sparse_mult_SAT_SB(const mxArray* A_m, const mxArray* B_m);
   // Computes Aᵀ·B where A is sparse and B is dense. The result is sparse.
-  static mxArray *Sparse_mult_SAT_B(const mxArray *A_m, const mxArray *B_m);
+  static mxArray* Sparse_mult_SAT_B(const mxArray* A_m, const mxArray* B_m);
   // Computes Aᵀ·B where A is sparse and B is dense. The result is dense.
-  static mxArray *mult_SAT_B(const mxArray *A_m, const mxArray *B_m);
+  static mxArray* mult_SAT_B(const mxArray* A_m, const mxArray* B_m);
   // Computes A−B where A and B are sparse. The result is sparse.
-  static mxArray *Sparse_subtract_SA_SB(const mxArray *A_m, const mxArray *B_m);
+  static mxArray* Sparse_subtract_SA_SB(const mxArray* A_m, const mxArray* B_m);
   // Computes A−B where A and B are dense. The result is dense.
-  static mxArray *subtract_A_B(const mxArray *A_m, const mxArray *B_m);
+  static mxArray* subtract_A_B(const mxArray* A_m, const mxArray* B_m);
 
   void compute_block_time(int my_Per_u_, bool evaluate, bool no_derivatives);
   bool compute_complete(bool no_derivatives);
@@ -229,28 +244,33 @@ private:
   pair<bool, double> compute_complete(double lambda);
 
 public:
-  Interpreter(Evaluate &evaluator_arg, double *params_arg, double *y_arg, double *ya_arg, double *x_arg, double *steady_y_arg,
-              double *direction_arg, int y_size_arg,
-              int nb_row_x_arg, int periods_arg, int y_kmin_arg, int y_kmax_arg,
-              int maxit_arg_, double solve_tolf_arg, double markowitz_c_arg,
-              int minimal_solving_periods_arg, int stack_solve_algo_arg, int solve_algo_arg,
-              bool print_arg, const mxArray *GlobalTemporaryTerms_arg,
-              bool steady_state_arg, bool block_decomposed_arg, int col_x_arg, int col_y_arg, const BasicSymbolTable &symbol_table_arg, int verbosity_arg);
-  pair<bool, vector<int>> extended_path(const string &file_name, bool evaluate, int block, int nb_periods, const vector<s_plan> &sextended_path, const vector<s_plan> &sconstrained_extended_path, const vector<string> &dates, const table_conditional_global_type &table_conditional_global);
-  pair<bool, vector<int>> compute_blocks(const string &file_name, bool evaluate, int block);
+  Interpreter(Evaluate& evaluator_arg, double* params_arg, double* y_arg, double* ya_arg,
+              double* x_arg, double* steady_y_arg, double* direction_arg, int y_size_arg,
+              int nb_row_x_arg, int periods_arg, int y_kmin_arg, int y_kmax_arg, int maxit_arg_,
+              double solve_tolf_arg, double markowitz_c_arg, int minimal_solving_periods_arg,
+              int stack_solve_algo_arg, int solve_algo_arg, bool print_arg,
+              const mxArray* GlobalTemporaryTerms_arg, bool steady_state_arg,
+              bool block_decomposed_arg, int col_x_arg, int col_y_arg,
+              const BasicSymbolTable& symbol_table_arg, int verbosity_arg);
+  pair<bool, vector<int>>
+  extended_path(const string& file_name, bool evaluate, int block, int nb_periods,
+                const vector<s_plan>& sextended_path,
+                const vector<s_plan>& sconstrained_extended_path, const vector<string>& dates,
+                const table_conditional_global_type& table_conditional_global);
+  pair<bool, vector<int>> compute_blocks(const string& file_name, bool evaluate, int block);
   void Close_SaveCode();
 
-  inline mxArray *
+  inline mxArray*
   get_jacob(int block_num) const
   {
     return jacobian_block[block_num];
   }
-  inline mxArray *
+  inline mxArray*
   get_jacob_exo(int block_num) const
   {
     return jacobian_exo_block[block_num];
   }
-  inline mxArray *
+  inline mxArray*
   get_jacob_exo_det(int block_num) const
   {
     return jacobian_det_exo_block[block_num];
@@ -260,7 +280,7 @@ public:
   {
     return residual;
   }
-  inline mxArray *
+  inline mxArray*
   get_Temporary_Terms() const
   {
     return GlobalTemporaryTerms;
diff --git a/mex/sources/bytecode/Mem_Mngr.cc b/mex/sources/bytecode/Mem_Mngr.cc
index 268bd63c1e3cd55deeb005540fff46ac373232c3..2a059b5d5a88d1210716cba58e871bd80a5f1d99 100644
--- a/mex/sources/bytecode/Mem_Mngr.cc
+++ b/mex/sources/bytecode/Mem_Mngr.cc
@@ -51,17 +51,18 @@ Mem_Mngr::init_CHUNK_BLCK_SIZE(int u_count)
   CHUNK_BLCK_SIZE = u_count;
 }
 
-NonZeroElem *
+NonZeroElem*
 Mem_Mngr::mxMalloc_NZE()
 {
   long unsigned int i;
   if (!Chunk_Stack.empty()) /*An unused block of memory available inside the heap*/
     {
-      NonZeroElem *p1 = Chunk_Stack.back();
+      NonZeroElem* p1 = Chunk_Stack.back();
       Chunk_Stack.pop_back();
       return p1;
     }
-  else if (CHUNK_heap_pos < CHUNK_SIZE) /*there is enough allocated memory space available we keep it at the top of the heap*/
+  else if (CHUNK_heap_pos < CHUNK_SIZE) /*there is enough allocated memory space available we keep
+                                           it at the top of the heap*/
     {
       i = CHUNK_heap_pos++;
       return NZE_Mem_add[i];
@@ -70,43 +71,54 @@ Mem_Mngr::mxMalloc_NZE()
     {
       CHUNK_SIZE += CHUNK_BLCK_SIZE;
       Nb_CHUNK++;
-      NZE_Mem = static_cast<NonZeroElem *>(mxMalloc(CHUNK_BLCK_SIZE*sizeof(NonZeroElem))); /*The block of memory allocated*/
-      test_mxMalloc(NZE_Mem, __LINE__, __FILE__, __func__, CHUNK_BLCK_SIZE*sizeof(NonZeroElem));
+      NZE_Mem = static_cast<NonZeroElem*>(
+          mxMalloc(CHUNK_BLCK_SIZE * sizeof(NonZeroElem))); /*The block of memory allocated*/
+      test_mxMalloc(NZE_Mem, __LINE__, __FILE__, __func__, CHUNK_BLCK_SIZE * sizeof(NonZeroElem));
       NZE_Mem_Allocated.push_back(NZE_Mem);
       if (!NZE_Mem)
         mexPrintf("Not enough memory available\n");
       if (NZE_Mem_add)
         {
-          NZE_Mem_add = static_cast<NonZeroElem **>(mxRealloc(NZE_Mem_add, CHUNK_SIZE*sizeof(NonZeroElem *))); /*We have to redefine the size of pointer on the memory*/
-          test_mxMalloc(NZE_Mem_add, __LINE__, __FILE__, __func__, CHUNK_SIZE*sizeof(NonZeroElem *));
+          NZE_Mem_add = static_cast<NonZeroElem**>(mxRealloc(
+              NZE_Mem_add,
+              CHUNK_SIZE
+                  * sizeof(
+                      NonZeroElem*))); /*We have to redefine the size of pointer on the memory*/
+          test_mxMalloc(NZE_Mem_add, __LINE__, __FILE__, __func__,
+                        CHUNK_SIZE * sizeof(NonZeroElem*));
         }
       else
         {
-          NZE_Mem_add = static_cast<NonZeroElem **>(mxMalloc(CHUNK_SIZE*sizeof(NonZeroElem *))); /*We have to define the size of pointer on the memory*/
-          test_mxMalloc(NZE_Mem_add, __LINE__, __FILE__, __func__, CHUNK_SIZE*sizeof(NonZeroElem *));
+          NZE_Mem_add = static_cast<NonZeroElem**>(mxMalloc(
+              CHUNK_SIZE
+              * sizeof(NonZeroElem*))); /*We have to define the size of pointer on the memory*/
+          test_mxMalloc(NZE_Mem_add, __LINE__, __FILE__, __func__,
+                        CHUNK_SIZE * sizeof(NonZeroElem*));
         }
 
       if (!NZE_Mem_add)
         mexPrintf("Not enough memory available\n");
       for (i = CHUNK_heap_pos; i < CHUNK_SIZE; i++)
-        NZE_Mem_add[i] = const_cast<NonZeroElem *>(NZE_Mem+(i-CHUNK_heap_pos));
+        NZE_Mem_add[i] = const_cast<NonZeroElem*>(NZE_Mem + (i - CHUNK_heap_pos));
       i = CHUNK_heap_pos++;
       return NZE_Mem_add[i];
     }
 }
 
 void
-Mem_Mngr::mxFree_NZE(void *pos)
+Mem_Mngr::mxFree_NZE(void* pos)
 {
   unsigned int i;
   ptrdiff_t gap;
   for (i = 0; i < Nb_CHUNK; i++)
     {
-      gap = (reinterpret_cast<ptrdiff_t>(pos)-reinterpret_cast<ptrdiff_t>(NZE_Mem_add[i*CHUNK_BLCK_SIZE]))/sizeof(NonZeroElem);
+      gap = (reinterpret_cast<ptrdiff_t>(pos)
+             - reinterpret_cast<ptrdiff_t>(NZE_Mem_add[i * CHUNK_BLCK_SIZE]))
+            / sizeof(NonZeroElem);
       if (gap < CHUNK_BLCK_SIZE && gap >= 0)
         break;
     }
-  Chunk_Stack.push_back(static_cast<NonZeroElem *>(pos));
+  Chunk_Stack.push_back(static_cast<NonZeroElem*>(pos));
 }
 
 void
diff --git a/mex/sources/bytecode/Mem_Mngr.hh b/mex/sources/bytecode/Mem_Mngr.hh
index b3b0ca8bfdc4876196154d89da1f1d05a0f90402..9ba250ca1bc3d039d14cfebadb655773856e67fd 100644
--- a/mex/sources/bytecode/Mem_Mngr.hh
+++ b/mex/sources/bytecode/Mem_Mngr.hh
@@ -20,9 +20,9 @@
 #ifndef _MEM_MNGR_HH
 #define _MEM_MNGR_HH
 
+#include <fstream>
 #include <string>
 #include <vector>
-#include <fstream>
 
 #include "ErrorHandling.hh"
 
@@ -35,26 +35,27 @@ struct NonZeroElem
   NonZeroElem *NZE_R_N, *NZE_C_N;
 };
 
-using v_NonZeroElem = vector<NonZeroElem *>;
+using v_NonZeroElem = vector<NonZeroElem*>;
 
 class Mem_Mngr
 {
 public:
   void init_Mem();
-  void mxFree_NZE(void *pos);
-  NonZeroElem *mxMalloc_NZE();
+  void mxFree_NZE(void* pos);
+  NonZeroElem* mxMalloc_NZE();
   void init_CHUNK_BLCK_SIZE(int u_count);
   void Free_All();
   Mem_Mngr();
   void fixe_file_name(string filename_arg);
   bool swp_f;
+
 private:
   v_NonZeroElem Chunk_Stack;
   unsigned int CHUNK_SIZE, CHUNK_BLCK_SIZE, Nb_CHUNK;
   unsigned int CHUNK_heap_pos;
-  NonZeroElem **NZE_Mem_add;
-  NonZeroElem *NZE_Mem;
-  vector<NonZeroElem *> NZE_Mem_Allocated;
+  NonZeroElem** NZE_Mem_add;
+  NonZeroElem* NZE_Mem;
+  vector<NonZeroElem*> NZE_Mem_Allocated;
   int swp_f_b;
   fstream SaveCode_swp;
   string filename_mem;
diff --git a/mex/sources/bytecode/bytecode.cc b/mex/sources/bytecode/bytecode.cc
index d74811bac22d6e81f388f3983fb1996504a68b57..ed79f2a0c696e6fd00b6dbd3b22304a731641bf0 100644
--- a/mex/sources/bytecode/bytecode.cc
+++ b/mex/sources/bytecode/bytecode.cc
@@ -17,20 +17,20 @@
  * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+#include <algorithm>
 #include <cmath>
 #include <type_traits>
-#include <algorithm>
 
-#include "Interpreter.hh"
 #include "ErrorHandling.hh"
+#include "Interpreter.hh"
 
 string
-Get_Argument(const mxArray *prhs)
+Get_Argument(const mxArray* prhs)
 {
-  const mxArray *mxa = prhs;
+  const mxArray* mxa = prhs;
   auto buflen = mwSize(mxGetM(mxa) * mxGetN(mxa) + 1);
-  char *first_argument;
-  first_argument = static_cast<char *>(mxCalloc(buflen, sizeof(char)));
+  char* first_argument;
+  first_argument = static_cast<char*>(mxCalloc(buflen, sizeof(char)));
   size_t status = mxGetString(mxa, first_argument, buflen);
   if (status != 0)
     mexWarnMsgTxt("Not enough space. The first argument is truncated.");
@@ -49,20 +49,14 @@ deblank(string x)
 }
 
 void
-Get_Arguments_and_global_variables(int nrhs,
-                                   const mxArray *prhs[],
-                                   double *yd[], size_t &row_y, size_t &col_y,
-                                   double *xd[], size_t &row_x, size_t &col_x,
-                                   double *params[],
-                                   double *steady_yd[], size_t &steady_row_y, size_t &steady_col_y,
-                                   int &periods,
-                                   mxArray **block_structur,
-                                   bool &steady_state, bool &block_decomposed,
-                                   bool &evaluate, int &block,
-                                   const mxArray **M_, const mxArray **options_,
-                                   bool &print,
-                                   const mxArray **GlobalTemporaryTerms,
-                                   bool *extended_path, mxArray **ep_struct)
+Get_Arguments_and_global_variables(int nrhs, const mxArray* prhs[], double* yd[], size_t& row_y,
+                                   size_t& col_y, double* xd[], size_t& row_x, size_t& col_x,
+                                   double* params[], double* steady_yd[], size_t& steady_row_y,
+                                   size_t& steady_col_y, int& periods, mxArray** block_structur,
+                                   bool& steady_state, bool& block_decomposed, bool& evaluate,
+                                   int& block, const mxArray** M_, const mxArray** options_,
+                                   bool& print, const mxArray** GlobalTemporaryTerms,
+                                   bool* extended_path, mxArray** ep_struct)
 {
   int count_array_argument {0};
   *extended_path = false;
@@ -115,82 +109,83 @@ Get_Arguments_and_global_variables(int nrhs,
             }
           count_array_argument++;
         }
+      else if (Get_Argument(prhs[i]) == "static")
+        steady_state = true;
+      else if (Get_Argument(prhs[i]) == "dynamic")
+        steady_state = false;
+      else if (Get_Argument(prhs[i]) == "block_decomposed")
+        block_decomposed = true;
+      else if (Get_Argument(prhs[i]) == "evaluate")
+        evaluate = true;
+      else if (Get_Argument(prhs[i]) == "print")
+        print = true;
       else
-        if (Get_Argument(prhs[i]) == "static")
-          steady_state = true;
-        else if (Get_Argument(prhs[i]) == "dynamic")
-          steady_state = false;
-        else if (Get_Argument(prhs[i]) == "block_decomposed")
-          block_decomposed = true;
-        else if (Get_Argument(prhs[i]) == "evaluate")
-          evaluate = true;
-        else if (Get_Argument(prhs[i]) == "print")
-          print = true;
-        else
-          {
-            if (Get_Argument(prhs[i]).substr(0, 6) == "block=")
-              {
-                try
-                  {
-                    block = stoi(Get_Argument(prhs[i]).substr(6))-1;
-                  }
-                catch (...)
-                  {
-                    throw FatalException{"ERROR: incorrect syntax for the 'block=' option"};
-                  }
-              }
-            else if (Get_Argument(prhs[i]).substr(0, 13) == "extended_path")
-              {
-                *extended_path = true;
-                if ((i+1) >= nrhs)
-                  *ep_struct = nullptr;
-                else
-                  {
-                    *ep_struct = mxDuplicateArray(prhs[i + 1]);
-                    i++;
-                  }
-              }
-            else
-              throw FatalException{"In main, unknown argument : " + Get_Argument(prhs[i])};
-          }
+        {
+          if (Get_Argument(prhs[i]).substr(0, 6) == "block=")
+            {
+              try
+                {
+                  block = stoi(Get_Argument(prhs[i]).substr(6)) - 1;
+                }
+              catch (...)
+                {
+                  throw FatalException {"ERROR: incorrect syntax for the 'block=' option"};
+                }
+            }
+          else if (Get_Argument(prhs[i]).substr(0, 13) == "extended_path")
+            {
+              *extended_path = true;
+              if ((i + 1) >= nrhs)
+                *ep_struct = nullptr;
+              else
+                {
+                  *ep_struct = mxDuplicateArray(prhs[i + 1]);
+                  i++;
+                }
+            }
+          else
+            throw FatalException {"In main, unknown argument : " + Get_Argument(prhs[i])};
+        }
     }
   if (steady_state)
     {
       if (count_array_argument < 5)
-        throw FatalException{"In a static context, the following arguments have to be indicated: M_, options_, y, x, params"};
+        throw FatalException {"In a static context, the following arguments have to be indicated: "
+                              "M_, options_, y, x, params"};
       if (count_array_argument < 7)
         periods = 1;
     }
   else
     {
       if (count_array_argument < 7)
-        throw FatalException{"In a dynamic context, the following arguments have to be indicated: M_, options_, y, x, params, steady_state, periods"};
+        throw FatalException {"In a dynamic context, the following arguments have to be indicated: "
+                              "M_, options_, y, x, params, steady_state, periods"};
     }
 }
 
 /* The gateway routine */
 void
-mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
+mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
 {
   const mxArray *M_, *options_;
-  const mxArray *GlobalTemporaryTerms {nullptr};
-  mxArray *block_structur = nullptr;
+  const mxArray* GlobalTemporaryTerms {nullptr};
+  mxArray* block_structur = nullptr;
   size_t i, row_y = 0, col_y = 0, row_x = 0, col_x = 0;
   size_t steady_row_y, steady_col_y;
   int y_kmin = 0, y_kmax = 0;
   int periods {1};
-  double *direction;
+  double* direction;
   bool steady_state = false;
   bool block_decomposed {false};
   bool evaluate = false;
   int block = -1;
-  double *params = nullptr;
+  double* params = nullptr;
   double *yd = nullptr, *xd = nullptr;
   bool print = false; // Whether the “print” command is requested
-  int verbosity {1}; // Corresponds to options_.verbosity
-  double *steady_yd = nullptr;
+  int verbosity {1};  // Corresponds to options_.verbosity
+  double* steady_yd = nullptr;
   bool extended_path;
-  mxArray *extended_path_struct;
+  mxArray* extended_path_struct;
 
   table_conditional_local_type conditional_local;
   vector<s_plan> sextended_path, sconditional_extended_path;
@@ -206,19 +201,12 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
 
   try
     {
-      Get_Arguments_and_global_variables(nrhs, prhs,
-                                         &yd, row_y, col_y,
-                                         &xd, row_x, col_x,
-                                         &params,
-                                         &steady_yd, steady_row_y, steady_col_y,
-                                         periods,
-                                         &block_structur,
-                                         steady_state, block_decomposed, evaluate, block,
-                                         &M_, &options_,
-                                         print, &GlobalTemporaryTerms,
-                                         &extended_path, &extended_path_struct);
+      Get_Arguments_and_global_variables(
+          nrhs, prhs, &yd, row_y, col_y, &xd, row_x, col_x, &params, &steady_yd, steady_row_y,
+          steady_col_y, periods, &block_structur, steady_state, block_decomposed, evaluate, block,
+          &M_, &options_, print, &GlobalTemporaryTerms, &extended_path, &extended_path_struct);
     }
-  catch (GeneralException &feh)
+  catch (GeneralException& feh)
     {
       mexErrMsgTxt(feh.message.c_str());
     }
@@ -226,57 +214,68 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
   mexPrintf("**************************************\n");
 #endif
 
-  BasicSymbolTable symbol_table{M_};
+  BasicSymbolTable symbol_table {M_};
   vector<string> dates;
 
   if (extended_path)
     {
       if (!extended_path_struct)
         mexErrMsgTxt("The 'extended_path' option must be followed by the extended_path descriptor");
-      mxArray *date_str = mxGetField(extended_path_struct, 0, "date_str");
+      mxArray* date_str = mxGetField(extended_path_struct, 0, "date_str");
       if (!date_str)
-        mexErrMsgTxt("The extended_path description structure does not contain the member: date_str");
+        mexErrMsgTxt(
+            "The extended_path description structure does not contain the member: date_str");
       int nb_periods = mxGetM(date_str) * mxGetN(date_str);
 
-      mxArray *constrained_vars_ = mxGetField(extended_path_struct, 0, "constrained_vars_");
+      mxArray* constrained_vars_ = mxGetField(extended_path_struct, 0, "constrained_vars_");
       if (!constrained_vars_)
-        mexErrMsgTxt("The extended_path description structure does not contain the member: constrained_vars_");
-      mxArray *constrained_paths_ = mxGetField(extended_path_struct, 0, "constrained_paths_");
+        mexErrMsgTxt("The extended_path description structure does not contain the member: "
+                     "constrained_vars_");
+      mxArray* constrained_paths_ = mxGetField(extended_path_struct, 0, "constrained_paths_");
       if (!constrained_paths_)
-        mexErrMsgTxt("The extended_path description structure does not contain the member: constrained_paths_");
-      mxArray *constrained_int_date_ = mxGetField(extended_path_struct, 0, "constrained_int_date_");
+        mexErrMsgTxt("The extended_path description structure does not contain the member: "
+                     "constrained_paths_");
+      mxArray* constrained_int_date_ = mxGetField(extended_path_struct, 0, "constrained_int_date_");
       if (!constrained_int_date_)
-        mexErrMsgTxt("The extended_path description structure does not contain the member: constrained_int_date_");
-      mxArray *constrained_perfect_foresight_ = mxGetField(extended_path_struct, 0, "constrained_perfect_foresight_");
+        mexErrMsgTxt("The extended_path description structure does not contain the member: "
+                     "constrained_int_date_");
+      mxArray* constrained_perfect_foresight_
+          = mxGetField(extended_path_struct, 0, "constrained_perfect_foresight_");
       if (!constrained_perfect_foresight_)
-        mexErrMsgTxt("The extended_path description structure does not contain the member: constrained_perfect_foresight_");
-      mxArray *shock_var_ = mxGetField(extended_path_struct, 0, "shock_vars_");
+        mexErrMsgTxt("The extended_path description structure does not contain the member: "
+                     "constrained_perfect_foresight_");
+      mxArray* shock_var_ = mxGetField(extended_path_struct, 0, "shock_vars_");
       if (!shock_var_)
-        mexErrMsgTxt("The extended_path description structure does not contain the member: shock_vars_");
-      mxArray *shock_paths_ = mxGetField(extended_path_struct, 0, "shock_paths_");
+        mexErrMsgTxt(
+            "The extended_path description structure does not contain the member: shock_vars_");
+      mxArray* shock_paths_ = mxGetField(extended_path_struct, 0, "shock_paths_");
       if (!shock_paths_)
-        mexErrMsgTxt("The extended_path description structure does not contain the member: shock_paths_");
-      mxArray *shock_int_date_ = mxGetField(extended_path_struct, 0, "shock_int_date_");
+        mexErrMsgTxt(
+            "The extended_path description structure does not contain the member: shock_paths_");
+      mxArray* shock_int_date_ = mxGetField(extended_path_struct, 0, "shock_int_date_");
       if (!shock_int_date_)
-        mexErrMsgTxt("The extended_path description structure does not contain the member: shock_int_date_");
-      mxArray *shock_str_date_ = mxGetField(extended_path_struct, 0, "shock_str_date_");
+        mexErrMsgTxt(
+            "The extended_path description structure does not contain the member: shock_int_date_");
+      mxArray* shock_str_date_ = mxGetField(extended_path_struct, 0, "shock_str_date_");
       if (!shock_str_date_)
-        mexErrMsgTxt("The extended_path description structure does not contain the member: shock_str_date_");
+        mexErrMsgTxt(
+            "The extended_path description structure does not contain the member: shock_str_date_");
       int nb_constrained = mxGetM(constrained_vars_) * mxGetN(constrained_vars_);
       int nb_controlled = 0;
-      mxArray *options_cond_fcst_ = mxGetField(extended_path_struct, 0, "options_cond_fcst_");
-      mxArray *controlled_varexo = nullptr;
+      mxArray* options_cond_fcst_ = mxGetField(extended_path_struct, 0, "options_cond_fcst_");
+      mxArray* controlled_varexo = nullptr;
       if (options_cond_fcst_)
         {
           controlled_varexo = mxGetField(options_cond_fcst_, 0, "controlled_varexo");
           nb_controlled = mxGetM(controlled_varexo) * mxGetN(controlled_varexo);
           if (nb_controlled != nb_constrained)
-            mexErrMsgTxt("The number of exogenized variables and the number of exogenous controlled variables should be equal.");
+            mexErrMsgTxt("The number of exogenized variables and the number of exogenous "
+                         "controlled variables should be equal.");
         }
-      double *controlled_varexo_value = nullptr;
+      double* controlled_varexo_value = nullptr;
       if (controlled_varexo)
         controlled_varexo_value = mxGetPr(controlled_varexo);
-      double *constrained_var_value = mxGetPr(constrained_vars_);
+      double* constrained_var_value = mxGetPr(constrained_vars_);
       sconditional_extended_path.resize(nb_constrained);
       max_periods = 0;
       if (nb_constrained)
@@ -302,16 +301,19 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
         {
           sconditional_extended_path[i].exo_num = ceil(constrained_var_value[i]);
           sconditional_extended_path[i].var_num = ceil(controlled_varexo_value[i]);
-          mxArray *Array_constrained_paths_ = mxGetCell(constrained_paths_, i);
-          double *specific_constrained_paths_ = mxGetPr(Array_constrained_paths_);
-          double *specific_constrained_int_date_ = mxGetPr(mxGetCell(constrained_int_date_, i));
-          int nb_local_periods = mxGetM(Array_constrained_paths_) * mxGetN(Array_constrained_paths_);
-          int *constrained_int_date = static_cast<int *>(mxMalloc(nb_local_periods * sizeof(int)));
-          test_mxMalloc(constrained_int_date, __LINE__, __FILE__, __func__, nb_local_periods * sizeof(int));
+          mxArray* Array_constrained_paths_ = mxGetCell(constrained_paths_, i);
+          double* specific_constrained_paths_ = mxGetPr(Array_constrained_paths_);
+          double* specific_constrained_int_date_ = mxGetPr(mxGetCell(constrained_int_date_, i));
+          int nb_local_periods
+              = mxGetM(Array_constrained_paths_) * mxGetN(Array_constrained_paths_);
+          int* constrained_int_date = static_cast<int*>(mxMalloc(nb_local_periods * sizeof(int)));
+          test_mxMalloc(constrained_int_date, __LINE__, __FILE__, __func__,
+                        nb_local_periods * sizeof(int));
           if (nb_periods < nb_local_periods)
             mexErrMsgTxt(("The total number of simulation periods (" + to_string(nb_periods)
                           + ") is lesser than the number of periods in the shock definitions ("
-                          + to_string(nb_local_periods)).c_str());
+                          + to_string(nb_local_periods))
+                             .c_str());
 
           sconditional_extended_path[i].per_value.resize(nb_local_periods);
           sconditional_extended_path[i].value.resize(nb_periods);
@@ -324,47 +326,55 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
               conditional_local.var_exo = sconditional_extended_path[i].var_num - 1;
               conditional_local.var_endo = sconditional_extended_path[i].exo_num - 1;
               conditional_local.constrained_value = specific_constrained_paths_[j];
-              table_conditional_global[constrained_int_date[j]][sconditional_extended_path[i].exo_num - 1] = conditional_local;
-              sconditional_extended_path[i].per_value[j] = { constrained_int_date[j], specific_constrained_paths_[j] };
-              sconditional_extended_path[i].value[constrained_int_date[j]] = specific_constrained_paths_[j];
+              table_conditional_global[constrained_int_date[j]]
+                                      [sconditional_extended_path[i].exo_num - 1]
+                  = conditional_local;
+              sconditional_extended_path[i].per_value[j]
+                  = {constrained_int_date[j], specific_constrained_paths_[j]};
+              sconditional_extended_path[i].value[constrained_int_date[j]]
+                  = specific_constrained_paths_[j];
               max_periods = max(max_periods, constrained_int_date[j] + 1);
             }
           mxFree(constrained_int_date);
         }
       vector_table_conditional_local_type vv = table_conditional_global[0];
-      double *shock_var_value = mxGetPr(shock_var_);
+      double* shock_var_value = mxGetPr(shock_var_);
       int nb_shocks = mxGetM(shock_var_) * mxGetN(shock_var_);
       sextended_path.resize(nb_shocks);
       for (int i = 0; i < nb_shocks; i++)
         {
           sextended_path[i].exo_num = ceil(shock_var_value[i]);
-          mxArray *Array_shock_paths_ = mxGetCell(shock_paths_, i);
-          double *specific_shock_paths_ = mxGetPr(Array_shock_paths_);
-          double *specific_shock_int_date_ = mxGetPr(mxGetCell(shock_int_date_, i));
+          mxArray* Array_shock_paths_ = mxGetCell(shock_paths_, i);
+          double* specific_shock_paths_ = mxGetPr(Array_shock_paths_);
+          double* specific_shock_int_date_ = mxGetPr(mxGetCell(shock_int_date_, i));
           int nb_local_periods = mxGetM(Array_shock_paths_) * mxGetN(Array_shock_paths_);
           if (nb_periods < nb_local_periods)
             mexErrMsgTxt(("The total number of simulation periods (" + to_string(nb_periods)
                           + ") is lesser than the number of periods in the shock definitions ("
-                          + to_string(nb_local_periods)).c_str());
+                          + to_string(nb_local_periods))
+                             .c_str());
           sextended_path[i].per_value.resize(nb_local_periods);
           sextended_path[i].value.resize(nb_periods);
           for (int j = 0; j < nb_periods; j++)
             sextended_path[i].value[j] = 0;
           for (int j = 0; j < nb_local_periods; j++)
             {
-              sextended_path[i].per_value[j] = { static_cast<int>(specific_shock_int_date_[j]), specific_shock_paths_[j] };
-              sextended_path[i].value[static_cast<int>(specific_shock_int_date_[j]-1)] = specific_shock_paths_[j];
+              sextended_path[i].per_value[j]
+                  = {static_cast<int>(specific_shock_int_date_[j]), specific_shock_paths_[j]};
+              sextended_path[i].value[static_cast<int>(specific_shock_int_date_[j] - 1)]
+                  = specific_shock_paths_[j];
               max_periods = max(max_periods, static_cast<int>(specific_shock_int_date_[j]));
             }
         }
       for (int i = 0; i < nb_periods; i++)
         {
           int buflen = mxGetNumberOfElements(mxGetCell(date_str, i)) + 1;
-          char *buf = static_cast<char *>(mxCalloc(buflen, sizeof(char)));
+          char* buf = static_cast<char*>(mxCalloc(buflen, sizeof(char)));
           int info = mxGetString(mxGetCell(date_str, i), buf, buflen);
           if (info)
-            mexErrMsgTxt("Can not allocated memory to store the date_str in the extended path descriptor");
-          dates.emplace_back(buf); //string(Dates[i]);
+            mexErrMsgTxt(
+                "Can not allocated memory to store the date_str in the extended path descriptor");
+          dates.emplace_back(buf); // string(Dates[i]);
           mxFree(buf);
         }
     }
@@ -401,7 +411,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
       if (field < 0)
         mexErrMsgTxt("steady is not a field of options_");
     }
-  mxArray *temporarystruct {mxGetFieldByNumber(options_, 0, field)};
+  mxArray* temporarystruct {mxGetFieldByNumber(options_, 0, field)};
 
   field = mxGetFieldNumber(temporarystruct, "maxit");
   if (field < 0)
@@ -433,8 +443,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
 
   /* Solver tolerance with respect to the residual. Equals options_.solve_tolf
      in the static case, or options_.dynatol.f in the dynamic case */
-  double solve_tolf { [options_, steady_state]
-  {
+  double solve_tolf {[options_, steady_state] {
     if (steady_state)
       {
         int field {mxGetFieldNumber(options_, "solve_tolf")};
@@ -447,21 +456,21 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
         int field {mxGetFieldNumber(options_, "dynatol")};
         if (field < 0)
           mexErrMsgTxt("dynatol is not a field of options_");
-        mxArray *dynatol {mxGetFieldByNumber(options_, 0, field)};
+        mxArray* dynatol {mxGetFieldByNumber(options_, 0, field)};
         field = mxGetFieldNumber(dynatol, "f");
         if (field < 0)
           mexErrMsgTxt("f is not a field of options_.dynatol");
         return *mxGetPr(mxGetFieldByNumber(dynatol, 0, field));
       }
-  }() };
+  }()};
 
   field = mxGetFieldNumber(M_, "fname");
   if (field < 0)
     mexErrMsgTxt("fname is not a field of M_");
-  mxArray *mxa {mxGetFieldByNumber(M_, 0, field)};
+  mxArray* mxa {mxGetFieldByNumber(M_, 0, field)};
 
   size_t buflen = mxGetM(mxa) * mxGetN(mxa) + 1;
-  char *fname = static_cast<char *>(mxCalloc(buflen+1, sizeof(char)));
+  char* fname = static_cast<char*>(mxCalloc(buflen + 1, sizeof(char)));
   size_t status = mxGetString(mxa, fname, static_cast<int>(buflen));
   fname[buflen] = ' ';
   if (status != 0)
@@ -476,43 +485,68 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
     mexErrMsgTxt("Bytecode: Can't use option stack_solve_algo=1 or 6");
 
   if (steady_state && !evaluate && !print && (solve_algo < 5 || solve_algo > 8))
-    mexErrMsgTxt("Bytecode: solve_algo must be between 5 and 8 when using the internal steady state solver");
+    mexErrMsgTxt(
+        "Bytecode: solve_algo must be between 5 and 8 when using the internal steady state solver");
 
-  size_t size_of_direction = col_y*row_y*sizeof(double);
-  auto *y = static_cast<double *>(mxMalloc(size_of_direction));
+  size_t size_of_direction = col_y * row_y * sizeof(double);
+  auto* y = static_cast<double*>(mxMalloc(size_of_direction));
   test_mxMalloc(y, __LINE__, __FILE__, __func__, size_of_direction);
-  auto *ya = static_cast<double *>(mxMalloc(size_of_direction));
+  auto* ya = static_cast<double*>(mxMalloc(size_of_direction));
   test_mxMalloc(ya, __LINE__, __FILE__, __func__, size_of_direction);
-  direction = static_cast<double *>(mxMalloc(size_of_direction));
+  direction = static_cast<double*>(mxMalloc(size_of_direction));
   test_mxMalloc(direction, __LINE__, __FILE__, __func__, 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));
+  auto* x = static_cast<double*>(mxMalloc(col_x * row_x * sizeof(double)));
+  test_mxMalloc(x, __LINE__, __FILE__, __func__, col_x * row_x * sizeof(double));
 
-  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);
+  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);
 
-  const filesystem::path codfile {file_name + "/model/bytecode/" + (block_decomposed ? "block/" : "")
-    + (steady_state ? "static" : "dynamic") + ".cod"};
+  const filesystem::path codfile {file_name + "/model/bytecode/"
+                                  + (block_decomposed ? "block/" : "")
+                                  + (steady_state ? "static" : "dynamic") + ".cod"};
   Evaluate evaluator {codfile, steady_state, symbol_table};
 
-  Interpreter interprete {evaluator, params, y, ya, x, steady_yd, direction, static_cast<int>(row_y), static_cast<int>(row_x),
-                          periods, y_kmin, y_kmax, maxit_, solve_tolf,
-                          markowitz_c, minimal_solving_periods, stack_solve_algo,
-                          solve_algo, print, GlobalTemporaryTerms,
-                          steady_state, block_decomposed, static_cast<int>(col_x), static_cast<int>(col_y), symbol_table, verbosity};
+  Interpreter interprete {evaluator,
+                          params,
+                          y,
+                          ya,
+                          x,
+                          steady_yd,
+                          direction,
+                          static_cast<int>(row_y),
+                          static_cast<int>(row_x),
+                          periods,
+                          y_kmin,
+                          y_kmax,
+                          maxit_,
+                          solve_tolf,
+                          markowitz_c,
+                          minimal_solving_periods,
+                          stack_solve_algo,
+                          solve_algo,
+                          print,
+                          GlobalTemporaryTerms,
+                          steady_state,
+                          block_decomposed,
+                          static_cast<int>(col_x),
+                          static_cast<int>(col_y),
+                          symbol_table,
+                          verbosity};
   bool r;
   vector<int> blocks;
 
   try
     {
       if (extended_path)
-        tie(r, blocks) = interprete.extended_path(file_name, evaluate, block, max_periods, sextended_path, sconditional_extended_path, dates, table_conditional_global);
+        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);
     }
-  catch (GeneralException &feh)
+  catch (GeneralException& feh)
     {
       // Release the lock on dynamic.bin for MATLAB+Windows, see #1815
       interprete.Close_SaveCode();
@@ -524,30 +558,31 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
       if (evaluate)
         {
           vector<double> residual = interprete.get_residual();
-          plhs[0] = mxCreateDoubleMatrix(residual.size()/periods, periods, mxREAL);
+          plhs[0] = mxCreateDoubleMatrix(residual.size() / periods, periods, mxREAL);
           std::copy(residual.begin(), residual.end(), mxGetPr(plhs[0]));
         }
       else
         {
           int out_periods = extended_path ? max_periods + y_kmin : col_y;
           plhs[0] = mxCreateDoubleMatrix(row_y, out_periods, mxREAL);
-          std::copy_n(y, row_y*out_periods, mxGetPr(plhs[0]));
+          std::copy_n(y, row_y * out_periods, mxGetPr(plhs[0]));
         }
       if (nlhs > 1)
         {
           if (evaluate)
             {
               int jacob_field_number = 0, jacob_exo_field_number = 0,
-                jacob_exo_det_field_number = 0;
+                  jacob_exo_det_field_number = 0;
               bool dont_store_a_structure {false};
               if (!block_structur)
                 {
-                  const char *field_names[] = {"g1", "g1_x", "g1_xd"};
+                  const char* field_names[] = {"g1", "g1_x", "g1_xd"};
                   jacob_field_number = 0;
                   jacob_exo_field_number = 1;
                   jacob_exo_det_field_number = 2;
-                  mwSize dims[1] = { static_cast<mwSize>(blocks.size()) };
-                  plhs[1] = mxCreateStructArray(1, dims, std::extent_v<decltype(field_names)>, field_names);
+                  mwSize dims[1] = {static_cast<mwSize>(blocks.size())};
+                  plhs[1] = mxCreateStructArray(1, dims, std::extent_v<decltype(field_names)>,
+                                                field_names);
                 }
               else if (!mxIsStruct(block_structur))
                 {
@@ -559,42 +594,47 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
                   plhs[1] = block_structur;
                   jacob_field_number = mxAddField(plhs[1], "g1");
                   if (jacob_field_number == -1)
-                    mexErrMsgTxt("Fatal error in bytecode: in main, cannot add extra field jacob to the structArray");
+                    mexErrMsgTxt("Fatal error in bytecode: in main, cannot add extra field jacob "
+                                 "to the structArray");
                   jacob_exo_field_number = mxAddField(plhs[1], "g1_x");
                   if (jacob_exo_field_number == -1)
-                    mexErrMsgTxt("Fatal error in bytecode: in main, cannot add extra field jacob_exo to the structArray");
+                    mexErrMsgTxt("Fatal error in bytecode: in main, cannot add extra field "
+                                 "jacob_exo to the structArray");
                   jacob_exo_det_field_number = mxAddField(plhs[1], "g1_xd");
                   if (jacob_exo_det_field_number == -1)
-                    mexErrMsgTxt("Fatal error in bytecode: in main, cannot add extra field jacob_exo_det to the structArray");
+                    mexErrMsgTxt("Fatal error in bytecode: in main, cannot add extra field "
+                                 "jacob_exo_det to the structArray");
                 }
               if (!dont_store_a_structure)
                 for (size_t i {0}; i < blocks.size(); i++)
                   {
-                    mxSetFieldByNumber(plhs[1], i, jacob_field_number, interprete.get_jacob(blocks[i]));
+                    mxSetFieldByNumber(plhs[1], i, jacob_field_number,
+                                       interprete.get_jacob(blocks[i]));
                     if (!steady_state)
                       {
-                        mxSetFieldByNumber(plhs[1], i, jacob_exo_field_number, interprete.get_jacob_exo(blocks[i]));
-                        mxSetFieldByNumber(plhs[1], i, jacob_exo_det_field_number, interprete.get_jacob_exo_det(blocks[i]));
+                        mxSetFieldByNumber(plhs[1], i, jacob_exo_field_number,
+                                           interprete.get_jacob_exo(blocks[i]));
+                        mxSetFieldByNumber(plhs[1], i, jacob_exo_det_field_number,
+                                           interprete.get_jacob_exo_det(blocks[i]));
                       }
                   }
             }
           else
             {
               plhs[1] = mxCreateDoubleMatrix(row_x, col_x, mxREAL);
-              double *pind = mxGetPr(plhs[1]);
-              for (i = 0; i < row_x*col_x; i++)
+              double* pind = mxGetPr(plhs[1]);
+              for (i = 0; i < row_x * col_x; i++)
                 pind[i] = x[i];
             }
           if (nlhs > 2)
             {
               plhs[2] = mxCreateDoubleMatrix(row_y, col_y, mxREAL);
-              double *pind = mxGetPr(plhs[2]);
-              for (i = 0; i < row_y*col_y; i++)
+              double* pind = mxGetPr(plhs[2]);
+              for (i = 0; i < row_y * col_y; i++)
                 pind[i] = y[i];
               if (nlhs > 3)
                 plhs[3] = interprete.get_Temporary_Terms();
             }
-
         }
     }
   if (x)
diff --git a/mex/sources/dynblas.h b/mex/sources/dynblas.h
index 57e0d3432da15dba8ffc3d6abc5f5f3d40e7b76d..6956fd30e47703da2acc84b55b51a10faf1958e7 100644
--- a/mex/sources/dynblas.h
+++ b/mex/sources/dynblas.h
@@ -43,71 +43,67 @@ typedef int blas_int;
 #if defined(MATLAB_MEX_FILE) && defined(_WIN32)
 # define FORTRAN_WRAPPER(x) x
 #else
-# define FORTRAN_WRAPPER(x) x ## _
+# define FORTRAN_WRAPPER(x) x##_
 #endif
 
 #ifdef __cplusplus
-extern "C" {
+extern "C"
+{
 #endif
 
-  typedef const char *BLCHAR;
-  typedef const blas_int *CONST_BLINT;
-  typedef const double *CONST_BLDOU;
-  typedef const float *CONST_BLFLT;
-  typedef double *BLDOU;
-  typedef float *BLFLT;
+  typedef const char* BLCHAR;
+  typedef const blas_int* CONST_BLINT;
+  typedef const double* CONST_BLDOU;
+  typedef const float* CONST_BLFLT;
+  typedef double* BLDOU;
+  typedef float* BLFLT;
 
 #define dgemm FORTRAN_WRAPPER(dgemm)
-  void dgemm(BLCHAR transa, BLCHAR transb, CONST_BLINT m, CONST_BLINT n,
-             CONST_BLINT k, CONST_BLDOU alpha, CONST_BLDOU a, CONST_BLINT lda,
-             CONST_BLDOU b, CONST_BLINT ldb, CONST_BLDOU beta,
-             BLDOU c, CONST_BLINT ldc);
+  void dgemm(BLCHAR transa, BLCHAR transb, CONST_BLINT m, CONST_BLINT n, CONST_BLINT k,
+             CONST_BLDOU alpha, CONST_BLDOU a, CONST_BLINT lda, CONST_BLDOU b, CONST_BLINT ldb,
+             CONST_BLDOU beta, BLDOU c, CONST_BLINT ldc);
 
 #define sgemm FORTRAN_WRAPPER(sgemm)
-  void sgemm(BLCHAR transa, BLCHAR transb, CONST_BLINT m, CONST_BLINT n,
-             CONST_BLINT k, CONST_BLFLT alpha, CONST_BLFLT a, CONST_BLINT lda,
-             CONST_BLFLT b, CONST_BLINT ldb, CONST_BLFLT beta,
-             BLFLT c, CONST_BLINT ldc);
+  void sgemm(BLCHAR transa, BLCHAR transb, CONST_BLINT m, CONST_BLINT n, CONST_BLINT k,
+             CONST_BLFLT alpha, CONST_BLFLT a, CONST_BLINT lda, CONST_BLFLT b, CONST_BLINT ldb,
+             CONST_BLFLT beta, BLFLT c, CONST_BLINT ldc);
 
 #define dsymm FORTRAN_WRAPPER(dsymm)
-  void dsymm(BLCHAR side, BLCHAR uplo, CONST_BLINT m, CONST_BLINT n,
-             CONST_BLDOU alpha, CONST_BLDOU a, CONST_BLINT lda,
-             CONST_BLDOU b, CONST_BLINT ldb, CONST_BLDOU beta,
+  void dsymm(BLCHAR side, BLCHAR uplo, CONST_BLINT m, CONST_BLINT n, CONST_BLDOU alpha,
+             CONST_BLDOU a, CONST_BLINT lda, CONST_BLDOU b, CONST_BLINT ldb, CONST_BLDOU beta,
              BLDOU c, CONST_BLINT ldc);
 
 #define dgemv FORTRAN_WRAPPER(dgemv)
-  void dgemv(BLCHAR trans, CONST_BLINT m, CONST_BLINT n, CONST_BLDOU alpha,
-             CONST_BLDOU a, CONST_BLINT lda, CONST_BLDOU x, CONST_BLINT incx,
-             CONST_BLDOU beta, BLDOU y, CONST_BLINT incy);
+  void dgemv(BLCHAR trans, CONST_BLINT m, CONST_BLINT n, CONST_BLDOU alpha, CONST_BLDOU a,
+             CONST_BLINT lda, CONST_BLDOU x, CONST_BLINT incx, CONST_BLDOU beta, BLDOU y,
+             CONST_BLINT incy);
 
 #define dsymv FORTRAN_WRAPPER(dsymv)
-  void dsymv(BLCHAR uplo, CONST_BLINT m, CONST_BLDOU alpha, CONST_BLDOU a,
-             CONST_BLINT lda, CONST_BLDOU b, CONST_BLINT ldb, CONST_BLDOU beta,
-             BLDOU c, CONST_BLINT ldc);
+  void dsymv(BLCHAR uplo, CONST_BLINT m, CONST_BLDOU alpha, CONST_BLDOU a, CONST_BLINT lda,
+             CONST_BLDOU b, CONST_BLINT ldb, CONST_BLDOU beta, BLDOU c, CONST_BLINT ldc);
 
 #define dtrsv FORTRAN_WRAPPER(dtrsv)
-  void dtrsv(BLCHAR uplo, BLCHAR trans, BLCHAR diag, CONST_BLINT n,
-             CONST_BLDOU a, CONST_BLINT lda, BLDOU x, CONST_BLINT incx);
+  void dtrsv(BLCHAR uplo, BLCHAR trans, BLCHAR diag, CONST_BLINT n, CONST_BLDOU a, CONST_BLINT lda,
+             BLDOU x, CONST_BLINT incx);
 
 #define dtrmv FORTRAN_WRAPPER(dtrmv)
-  void dtrmv(BLCHAR uplo, BLCHAR trans, BLCHAR diag, CONST_BLINT n,
-             CONST_BLDOU a, CONST_BLINT lda, BLDOU x, CONST_BLINT incx);
+  void dtrmv(BLCHAR uplo, BLCHAR trans, BLCHAR diag, CONST_BLINT n, CONST_BLDOU a, CONST_BLINT lda,
+             BLDOU x, CONST_BLINT incx);
 
 #define daxpy FORTRAN_WRAPPER(daxpy)
-  void daxpy(CONST_BLINT n, CONST_BLDOU a, CONST_BLDOU x, CONST_BLINT incx,
-             BLDOU y, CONST_BLINT incy);
+  void daxpy(CONST_BLINT n, CONST_BLDOU a, CONST_BLDOU x, CONST_BLINT incx, BLDOU y,
+             CONST_BLINT incy);
 
 #define saxpy FORTRAN_WRAPPER(saxpy)
-  void saxpy(CONST_BLINT n, CONST_BLFLT a, CONST_BLFLT x, CONST_BLINT incx,
-             BLFLT y, CONST_BLINT incy);
+  void saxpy(CONST_BLINT n, CONST_BLFLT a, CONST_BLFLT x, CONST_BLINT incx, BLFLT y,
+             CONST_BLINT incy);
 
 #define dcopy FORTRAN_WRAPPER(dcopy)
-  void dcopy(CONST_BLINT n, CONST_BLDOU x, CONST_BLINT incx,
-             BLDOU y, CONST_BLINT incy);
+  void dcopy(CONST_BLINT n, CONST_BLDOU x, CONST_BLINT incx, BLDOU y, CONST_BLINT incy);
 
 #define zaxpy FORTRAN_WRAPPER(zaxpy)
-  void zaxpy(CONST_BLINT n, CONST_BLDOU a, CONST_BLDOU x, CONST_BLINT incx,
-             BLDOU y, CONST_BLINT incy);
+  void zaxpy(CONST_BLINT n, CONST_BLDOU a, CONST_BLDOU x, CONST_BLINT incx, BLDOU y,
+             CONST_BLINT incy);
 
 #define dscal FORTRAN_WRAPPER(dscal)
   void dscal(CONST_BLINT n, CONST_BLDOU a, BLDOU x, CONST_BLINT incx);
@@ -116,27 +112,23 @@ extern "C" {
   void sscal(CONST_BLINT n, CONST_BLDOU a, BLFLT x, CONST_BLINT incx);
 
 #define dtrsm FORTRAN_WRAPPER(dtrsm)
-  void dtrsm(BLCHAR side, BLCHAR uplo, BLCHAR transa, BLCHAR diag, CONST_BLINT m,
-             CONST_BLINT n, CONST_BLDOU alpha, CONST_BLDOU a, CONST_BLINT lda,
-             BLDOU b, CONST_BLINT ldb);
+  void dtrsm(BLCHAR side, BLCHAR uplo, BLCHAR transa, BLCHAR diag, CONST_BLINT m, CONST_BLINT n,
+             CONST_BLDOU alpha, CONST_BLDOU a, CONST_BLINT lda, BLDOU b, CONST_BLINT ldb);
 
 #define ddot FORTRAN_WRAPPER(ddot)
-  double ddot(CONST_BLINT n, CONST_BLDOU x, CONST_BLINT incx, CONST_BLDOU y,
-              CONST_BLINT incy);
+  double ddot(CONST_BLINT n, CONST_BLDOU x, CONST_BLINT incx, CONST_BLDOU y, CONST_BLINT incy);
 
 #define dsyr FORTRAN_WRAPPER(dsyr)
-  void dsyr(BLCHAR uplo, CONST_BLINT n, CONST_BLDOU alpha, CONST_BLDOU x,
-            CONST_BLINT incx, BLDOU a, CONST_BLINT lda);
+  void dsyr(BLCHAR uplo, CONST_BLINT n, CONST_BLDOU alpha, CONST_BLDOU x, CONST_BLINT incx, BLDOU a,
+            CONST_BLINT lda);
 
 #define dtrmm FORTRAN_WRAPPER(dtrmm)
-  void dtrmm(BLCHAR side, BLCHAR uplo, BLCHAR transa, BLCHAR diag, CONST_BLINT m,
-             CONST_BLINT n, CONST_BLDOU alpha, CONST_BLDOU a, CONST_BLINT lda,
-             BLDOU b, CONST_BLINT ldb);
+  void dtrmm(BLCHAR side, BLCHAR uplo, BLCHAR transa, BLCHAR diag, CONST_BLINT m, CONST_BLINT n,
+             CONST_BLDOU alpha, CONST_BLDOU a, CONST_BLINT lda, BLDOU b, CONST_BLINT ldb);
 
 #define strmm FORTRAN_WRAPPER(strmm)
-  void strmm(BLCHAR side, BLCHAR uplo, BLCHAR transa, BLCHAR diag, CONST_BLINT m,
-             CONST_BLINT n, CONST_BLFLT alpha, CONST_BLFLT a, CONST_BLINT lda,
-             BLFLT b, CONST_BLINT ldb);
+  void strmm(BLCHAR side, BLCHAR uplo, BLCHAR transa, BLCHAR diag, CONST_BLINT m, CONST_BLINT n,
+             CONST_BLFLT alpha, CONST_BLFLT a, CONST_BLINT lda, BLFLT b, CONST_BLINT ldb);
 
 #ifdef __cplusplus
 } /* extern "C" */
diff --git a/mex/sources/dynlapack.h b/mex/sources/dynlapack.h
index 59d394241c9b52c28469c55aa3f6cb38a4286be7..d17ed955a059c3563bcf172b49ef213b6c155d0c 100644
--- a/mex/sources/dynlapack.h
+++ b/mex/sources/dynlapack.h
@@ -43,115 +43,104 @@ typedef int lapack_int;
 #if defined(MATLAB_MEX_FILE) && defined(_WIN32)
 # define FORTRAN_WRAPPER(x) x
 #else
-# define FORTRAN_WRAPPER(x) x ## _
+# define FORTRAN_WRAPPER(x) x##_
 #endif
 
 #ifdef __cplusplus
-extern "C" {
+extern "C"
+{
 #endif
 
-  typedef const char *LACHAR;
-  typedef const lapack_int *CONST_LAINT;
-  typedef lapack_int *LAINT;
-  typedef const double *CONST_LADOU;
-  typedef double *LADOU;
-  typedef lapack_int (*DGGESCRIT)(const double *, const double *, const double *);
-  typedef lapack_int (*SGGESCRIT)(const float *, const float *, const float *);
-  typedef float *LAFLT;
-  typedef const float *CONST_LAFLT;
-  typedef lapack_int *CONST_LALOG; /*logical*/
+  typedef const char* LACHAR;
+  typedef const lapack_int* CONST_LAINT;
+  typedef lapack_int* LAINT;
+  typedef const double* CONST_LADOU;
+  typedef double* LADOU;
+  typedef lapack_int (*DGGESCRIT)(const double*, const double*, const double*);
+  typedef lapack_int (*SGGESCRIT)(const float*, const float*, const float*);
+  typedef float* LAFLT;
+  typedef const float* CONST_LAFLT;
+  typedef lapack_int* CONST_LALOG; /*logical*/
 
 #define dgetrs FORTRAN_WRAPPER(dgetrs)
-  void dgetrs(LACHAR trans, CONST_LAINT n, CONST_LAINT nrhs, CONST_LADOU a, CONST_LAINT lda, CONST_LAINT ipiv,
-              LADOU b, CONST_LAINT ldb, LAINT info);
+  void dgetrs(LACHAR trans, CONST_LAINT n, CONST_LAINT nrhs, CONST_LADOU a, CONST_LAINT lda,
+              CONST_LAINT ipiv, LADOU b, CONST_LAINT ldb, LAINT info);
 
 #define dgetrf FORTRAN_WRAPPER(dgetrf)
-  void dgetrf(CONST_LAINT m, CONST_LAINT n, LADOU a,
-              CONST_LAINT lda, LAINT ipiv, LAINT info);
+  void dgetrf(CONST_LAINT m, CONST_LAINT n, LADOU a, CONST_LAINT lda, LAINT ipiv, LAINT info);
 
 #define dgetri FORTRAN_WRAPPER(dgetri)
   void dgetri(CONST_LAINT n, LADOU a, CONST_LAINT lda, CONST_LAINT ipiv, LADOU work,
               CONST_LAINT lwork, LAINT info);
 
 #define sgetrf FORTRAN_WRAPPER(sgetrf)
-  void sgetrf(CONST_LAINT m, CONST_LAINT n, LAFLT a,
-              CONST_LAINT lda, LAINT ipiv, LAINT info);
+  void sgetrf(CONST_LAINT m, CONST_LAINT n, LAFLT a, CONST_LAINT lda, LAINT ipiv, LAINT info);
 
 #define dgees FORTRAN_WRAPPER(dgees)
-  void dgees(LACHAR jobvs, LACHAR sort, const void *select,
-             CONST_LAINT n, LADOU a, CONST_LAINT lda, LAINT sdim,
-             LADOU wr, LADOU wi, LADOU vs, CONST_LAINT ldvs,
-             LADOU work, CONST_LAINT lwork, LAINT bwork, LAINT info);
+  void dgees(LACHAR jobvs, LACHAR sort, const void* select, CONST_LAINT n, LADOU a, CONST_LAINT lda,
+             LAINT sdim, LADOU wr, LADOU wi, LADOU vs, CONST_LAINT ldvs, LADOU work,
+             CONST_LAINT lwork, LAINT bwork, LAINT info);
 
 #define dgecon FORTRAN_WRAPPER(dgecon)
-  void dgecon(LACHAR norm, CONST_LAINT n, CONST_LADOU a, CONST_LAINT lda,
-              CONST_LADOU anorm, LADOU rnorm, LADOU work, LAINT iwork,
-              LAINT info);
+  void dgecon(LACHAR norm, CONST_LAINT n, CONST_LADOU a, CONST_LAINT lda, CONST_LADOU anorm,
+              LADOU rnorm, LADOU work, LAINT iwork, LAINT info);
 
 #define dtrexc FORTRAN_WRAPPER(dtrexc)
-  void dtrexc(LACHAR compq, CONST_LAINT n, LADOU t, CONST_LAINT ldt,
-              LADOU q, CONST_LAINT ldq, LAINT ifst, LAINT ilst, LADOU work,
-              LAINT info);
+  void dtrexc(LACHAR compq, CONST_LAINT n, LADOU t, CONST_LAINT ldt, LADOU q, CONST_LAINT ldq,
+              LAINT ifst, LAINT ilst, LADOU work, LAINT info);
 
 #define dtrsyl FORTRAN_WRAPPER(dtrsyl)
-  void dtrsyl(LACHAR trana, LACHAR tranb, CONST_LAINT isgn, CONST_LAINT m,
-              CONST_LAINT n, CONST_LADOU a, CONST_LAINT lda, CONST_LADOU b,
-              CONST_LAINT ldb, LADOU c, CONST_LAINT ldc, LADOU scale,
-              LAINT info);
+  void dtrsyl(LACHAR trana, LACHAR tranb, CONST_LAINT isgn, CONST_LAINT m, CONST_LAINT n,
+              CONST_LADOU a, CONST_LAINT lda, CONST_LADOU b, CONST_LAINT ldb, LADOU c,
+              CONST_LAINT ldc, LADOU scale, LAINT info);
 
 #define dpotrf FORTRAN_WRAPPER(dpotrf)
-  void dpotrf(LACHAR uplo, CONST_LAINT n, LADOU a, CONST_LAINT lda,
-              LAINT info);
+  void dpotrf(LACHAR uplo, CONST_LAINT n, LADOU a, CONST_LAINT lda, LAINT info);
 
 #define dppsv FORTRAN_WRAPPER(dppsv)
   void dppsv(LACHAR uplo, CONST_LAINT n, CONST_LAINT m, LADOU a, LADOU b, CONST_LAINT ldb,
              LAINT info);
 
 #define dpotri FORTRAN_WRAPPER(dpotri)
-  void dpotri(LACHAR uplo, CONST_LAINT n, LADOU a, CONST_LAINT lda,
-              LAINT info);
+  void dpotri(LACHAR uplo, CONST_LAINT n, LADOU a, CONST_LAINT lda, LAINT info);
 
 #define dtrtri FORTRAN_WRAPPER(dtrtri)
-  void dtrtri(LACHAR uplo, LACHAR diag, CONST_LAINT n, LADOU a, CONST_LAINT lda,
-              LAINT info);
+  void dtrtri(LACHAR uplo, LACHAR diag, CONST_LAINT n, LADOU a, CONST_LAINT lda, LAINT info);
 
 #define dgges FORTRAN_WRAPPER(dgges)
-  void dgges(LACHAR jobvsl, LACHAR jobvsr, LACHAR sort, DGGESCRIT delztg,
-             CONST_LAINT n, LADOU a, CONST_LAINT lda, LADOU b, CONST_LAINT ldb,
-             LAINT sdim, LADOU alphar, LADOU alphai, LADOU beta,
-             LADOU vsl, CONST_LAINT ldvsl, LADOU vsr, CONST_LAINT ldvsr,
-             LADOU work, CONST_LAINT lwork, LAINT bwork, LAINT info);
+  void dgges(LACHAR jobvsl, LACHAR jobvsr, LACHAR sort, DGGESCRIT delztg, CONST_LAINT n, LADOU a,
+             CONST_LAINT lda, LADOU b, CONST_LAINT ldb, LAINT sdim, LADOU alphar, LADOU alphai,
+             LADOU beta, LADOU vsl, CONST_LAINT ldvsl, LADOU vsr, CONST_LAINT ldvsr, LADOU work,
+             CONST_LAINT lwork, LAINT bwork, LAINT info);
 
 #define sgges FORTRAN_WRAPPER(sgges)
-  void sgges(LACHAR jobvsl, LACHAR jobvsr, LACHAR sort, SGGESCRIT delztg,
-             CONST_LAINT n, LAFLT a, CONST_LAINT lda, LAFLT b, CONST_LAINT ldb,
-             LAINT sdim, LAFLT alphar, LAFLT alphai, LAFLT beta,
-             LAFLT vsl, CONST_LAINT ldvsl, LAFLT vsr, CONST_LAINT ldvsr,
-             LAFLT work, CONST_LAINT lwork, LAINT bwork, LAINT info);
+  void sgges(LACHAR jobvsl, LACHAR jobvsr, LACHAR sort, SGGESCRIT delztg, CONST_LAINT n, LAFLT a,
+             CONST_LAINT lda, LAFLT b, CONST_LAINT ldb, LAINT sdim, LAFLT alphar, LAFLT alphai,
+             LAFLT beta, LAFLT vsl, CONST_LAINT ldvsl, LAFLT vsr, CONST_LAINT ldvsr, LAFLT work,
+             CONST_LAINT lwork, LAINT bwork, LAINT info);
 
 #define dsyev FORTRAN_WRAPPER(dsyev)
-  void dsyev(LACHAR jobz, LACHAR uplo, CONST_LAINT n, LADOU a, CONST_LAINT lda,
-             LADOU w, LADOU work, CONST_LAINT lwork, LAINT info);
+  void dsyev(LACHAR jobz, LACHAR uplo, CONST_LAINT n, LADOU a, CONST_LAINT lda, LADOU w, LADOU work,
+             CONST_LAINT lwork, LAINT info);
 
 #define dsyevr FORTRAN_WRAPPER(dsyevr)
-  void dsyevr(LACHAR jobz, LACHAR range, LACHAR uplo, CONST_LAINT n, LADOU a,
-              CONST_LAINT lda, LADOU lv, LADOU vu, CONST_LAINT il, CONST_LAINT iu,
-              CONST_LADOU abstol, LAINT m, LADOU w, LADOU z, CONST_LAINT ldz,
-              LAINT isuppz, LADOU work, CONST_LAINT lwork, LAINT iwork, CONST_LAINT liwork,
-              LAINT info);
+  void dsyevr(LACHAR jobz, LACHAR range, LACHAR uplo, CONST_LAINT n, LADOU a, CONST_LAINT lda,
+              LADOU lv, LADOU vu, CONST_LAINT il, CONST_LAINT iu, CONST_LADOU abstol, LAINT m,
+              LADOU w, LADOU z, CONST_LAINT ldz, LAINT isuppz, LADOU work, CONST_LAINT lwork,
+              LAINT iwork, CONST_LAINT liwork, LAINT info);
 
 #define dgeqrf FORTRAN_WRAPPER(dgeqrf)
-  void dgeqrf(CONST_LAINT m, CONST_LAINT n, LADOU a, CONST_LAINT lda,
-              LADOU tau, LADOU work, CONST_LAINT lwork, LAINT info);
+  void dgeqrf(CONST_LAINT m, CONST_LAINT n, LADOU a, CONST_LAINT lda, LADOU tau, LADOU work,
+              CONST_LAINT lwork, LAINT info);
 
 #define sgeqrf FORTRAN_WRAPPER(sgeqrf)
-  void sgeqrf(CONST_LAINT m, CONST_LAINT n, LAFLT a, CONST_LAINT lda,
-              LAFLT tau, LAFLT work, CONST_LAINT lwork, LAINT info);
+  void sgeqrf(CONST_LAINT m, CONST_LAINT n, LAFLT a, CONST_LAINT lda, LAFLT tau, LAFLT work,
+              CONST_LAINT lwork, LAINT info);
 
 #define dormqr FORTRAN_WRAPPER(dormqr)
-  void dormqr(LACHAR side, LACHAR trans, CONST_LAINT m, CONST_LAINT n, CONST_LAINT k,
-              CONST_LADOU a, CONST_LAINT lda, CONST_LADOU tau, LADOU c, CONST_LAINT ldc,
-              LADOU work, CONST_LAINT lwork, LAINT info);
+  void dormqr(LACHAR side, LACHAR trans, CONST_LAINT m, CONST_LAINT n, CONST_LAINT k, CONST_LADOU a,
+              CONST_LAINT lda, CONST_LADOU tau, LADOU c, CONST_LAINT ldc, LADOU work,
+              CONST_LAINT lwork, LAINT info);
 
 #define dorgqr FORTRAN_WRAPPER(dorgqr)
   void dorgqr(CONST_LAINT m, CONST_LAINT n, CONST_LAINT k, LADOU a, CONST_LAINT lda,
@@ -162,12 +151,12 @@ extern "C" {
               CONST_LAFLT tau, LAFLT work, CONST_LAINT lwork, LAINT info);
 
 #define dgelqf FORTRAN_WRAPPER(dgelqf)
-  void dgelqf(CONST_LAINT m, CONST_LAINT n, LADOU a, CONST_LAINT lda, LADOU tau,
-              LADOU work, CONST_LAINT lwork, LAINT info);
+  void dgelqf(CONST_LAINT m, CONST_LAINT n, LADOU a, CONST_LAINT lda, LADOU tau, LADOU work,
+              CONST_LAINT lwork, LAINT info);
 
 #define sgelqf FORTRAN_WRAPPER(sgelqf)
-  void sgelqf(CONST_LAINT m, CONST_LAINT n, LAFLT a, CONST_LAINT lda, LAFLT tau,
-              LAFLT work, CONST_LAINT lwork, LAINT info);
+  void sgelqf(CONST_LAINT m, CONST_LAINT n, LAFLT a, CONST_LAINT lda, LAFLT tau, LAFLT work,
+              CONST_LAINT lwork, LAINT info);
 
 #define dorglq FORTRAN_WRAPPER(dorglq)
   void dorglq(CONST_LAINT m, CONST_LAINT n, CONST_LAINT k, LADOU a, CONST_LAINT lda,
@@ -178,8 +167,8 @@ extern "C" {
               CONST_LAFLT tau, LAFLT work, CONST_LAINT lwork, LAINT info);
 
 #define dgesv FORTRAN_WRAPPER(dgesv)
-  void dgesv(CONST_LAINT n, CONST_LAINT nrhs, LADOU a, CONST_LAINT lda, LAINT ipiv,
-             LADOU b, CONST_LAINT ldb, LAINT info);
+  void dgesv(CONST_LAINT n, CONST_LAINT nrhs, LADOU a, CONST_LAINT lda, LAINT ipiv, LADOU b,
+             CONST_LAINT ldb, LAINT info);
 
 #define dgesvd FORTRAN_WRAPPER(dgesvd)
   void dgesvd(LACHAR jobu, LACHAR jobvt, CONST_LAINT m, CONST_LAINT n, LADOU a, CONST_LAINT lda,
@@ -193,17 +182,17 @@ extern "C" {
 
 #define dtgsen FORTRAN_WRAPPER(dtgsen)
   void dtgsen(CONST_LAINT ijob, CONST_LALOG wantq, CONST_LALOG wantz, CONST_LALOG select,
-              CONST_LAINT n, LADOU a, CONST_LAINT lda, LADOU b, CONST_LAINT ldb,
-              LADOU alphar, LADOU alphai, LADOU beta, LADOU q, CONST_LAINT ldq,
-              LADOU z, CONST_LAINT ldz, LAINT m, LADOU pl, LADOU pr, LADOU dif, LADOU work,
-              CONST_LAINT lwork, LAINT iwork, CONST_LAINT liwork, LAINT info);
+              CONST_LAINT n, LADOU a, CONST_LAINT lda, LADOU b, CONST_LAINT ldb, LADOU alphar,
+              LADOU alphai, LADOU beta, LADOU q, CONST_LAINT ldq, LADOU z, CONST_LAINT ldz, LAINT m,
+              LADOU pl, LADOU pr, LADOU dif, LADOU work, CONST_LAINT lwork, LAINT iwork,
+              CONST_LAINT liwork, LAINT info);
 
 #define stgsen FORTRAN_WRAPPER(stgsen)
   void stgsen(CONST_LAINT ijob, CONST_LALOG wantq, CONST_LALOG wantz, CONST_LALOG select,
-              CONST_LAINT n, LAFLT a, CONST_LAINT lda, LAFLT b, CONST_LAINT ldb,
-              LAFLT alphar, LAFLT alphai, LAFLT beta, LAFLT q, CONST_LAINT ldq,
-              LAFLT z, CONST_LAINT ldz, LAINT m, LAFLT pl, LAFLT pr, LAFLT dif, LAFLT work,
-              CONST_LAINT lwork, LAINT iwork, CONST_LAINT liwork, LAINT info);
+              CONST_LAINT n, LAFLT a, CONST_LAINT lda, LAFLT b, CONST_LAINT ldb, LAFLT alphar,
+              LAFLT alphai, LAFLT beta, LAFLT q, CONST_LAINT ldq, LAFLT z, CONST_LAINT ldz, LAINT m,
+              LAFLT pl, LAFLT pr, LAFLT dif, LAFLT work, CONST_LAINT lwork, LAINT iwork,
+              CONST_LAINT liwork, LAINT info);
 
 #define dtgexc FORTRAN_WRAPPER(dtgexc)
   void dtgexc(CONST_LALOG wantq, CONST_LALOG wantz, CONST_LAINT n, LADOU a, CONST_LAINT lda,
@@ -216,19 +205,19 @@ extern "C" {
               LAINT ifst, LAINT ilst, LAFLT work, CONST_LAINT lwork, LAINT info);
 
 #define dgesdd FORTRAN_WRAPPER(dgesdd)
-  void dgesdd(LACHAR jobz, CONST_LAINT m, CONST_LAINT n, LADOU a, CONST_LAINT lda,
-              LADOU s, LADOU u, CONST_LAINT ldu, LADOU vt, CONST_LAINT ldvt, LADOU work,
-              CONST_LAINT lwork, LAINT iwork, LAINT info);
+  void dgesdd(LACHAR jobz, CONST_LAINT m, CONST_LAINT n, LADOU a, CONST_LAINT lda, LADOU s, LADOU u,
+              CONST_LAINT ldu, LADOU vt, CONST_LAINT ldvt, LADOU work, CONST_LAINT lwork,
+              LAINT iwork, LAINT info);
 
 #define sgesdd FORTRAN_WRAPPER(sgesdd)
-  void sgesdd(LACHAR jobz, CONST_LAINT m, CONST_LAINT n, LAFLT a, CONST_LAINT lda,
-              LAFLT s, LAFLT u, CONST_LAINT ldu, LAFLT vt, CONST_LAINT ldvt, LAFLT work,
-              CONST_LAINT lwork, LAINT iwork, LAINT info);
+  void sgesdd(LACHAR jobz, CONST_LAINT m, CONST_LAINT n, LAFLT a, CONST_LAINT lda, LAFLT s, LAFLT u,
+              CONST_LAINT ldu, LAFLT vt, CONST_LAINT ldvt, LAFLT work, CONST_LAINT lwork,
+              LAINT iwork, LAINT info);
 
 #define dgeev FORTRAN_WRAPPER(dgeev)
-  void dgeev(LACHAR jobvl, LACHAR jobvr, CONST_LAINT n, LADOU a, CONST_LAINT lda,
-             LADOU wr, LADOU wi, LADOU vl, CONST_LAINT ldvl, LADOU vr, CONST_LAINT ldvr,
-             LADOU work, CONST_LAINT lwork, LAINT info);
+  void dgeev(LACHAR jobvl, LACHAR jobvr, CONST_LAINT n, LADOU a, CONST_LAINT lda, LADOU wr,
+             LADOU wi, LADOU vl, CONST_LAINT ldvl, LADOU vr, CONST_LAINT ldvr, LADOU work,
+             CONST_LAINT lwork, LAINT info);
 
 #define dgeqp3 FORTRAN_WRAPPER(dgeqp3)
   void dgeqp3(CONST_LAINT m, CONST_LAINT n, LADOU a, CONST_LAINT lda, LAINT jpvt, LADOU tau,
diff --git a/mex/sources/dynumfpack.h b/mex/sources/dynumfpack.h
index c2d5ebb4d2355b77b28e5d50e65ba325ad69bde6..6597c2f2f10b39ae6710dd4ca35b04480596470d 100644
--- a/mex/sources/dynumfpack.h
+++ b/mex/sources/dynumfpack.h
@@ -37,7 +37,8 @@
    libmwumfpack, since there is no associated header */
 
 # ifdef __cplusplus
-extern "C" {
+extern "C"
+{
 # endif
 
   /* -------------------------------------------------------------------------- */
@@ -50,10 +51,10 @@ extern "C" {
 # define UMFPACK_INFO 90
 # define UMFPACK_CONTROL 20
   /* used in all UMFPACK_report_* routines: */
-# define UMFPACK_PRL 0                   /* print level */
+# define UMFPACK_PRL 0 /* print level */
   /* returned by all routines that use Info: */
 # define UMFPACK_OK (0)
-# define UMFPACK_STATUS 0        /* UMFPACK_OK, or other result */
+# define UMFPACK_STATUS 0 /* UMFPACK_OK, or other result */
 
 # ifdef _WIN64
 #  ifdef __cplusplus
@@ -63,42 +64,44 @@ extern "C" {
 #  endif
   typedef int64_t SuiteSparse_long;
 # else
-  typedef long SuiteSparse_long;
+typedef long SuiteSparse_long;
 # endif
 
   void umfpack_dl_defaults(double Control[UMFPACK_CONTROL]);
 
   SuiteSparse_long umfpack_dl_symbolic(SuiteSparse_long n_row, SuiteSparse_long n_col,
-                                       const SuiteSparse_long Ap [], const SuiteSparse_long Ai [],
-                                       const double Ax [], void **Symbolic,
-                                       const double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO]);
+                                       const SuiteSparse_long Ap[], const SuiteSparse_long Ai[],
+                                       const double Ax[], void** Symbolic,
+                                       const double Control[UMFPACK_CONTROL],
+                                       double Info[UMFPACK_INFO]);
 
-  SuiteSparse_long umfpack_dl_numeric(const SuiteSparse_long Ap [], const SuiteSparse_long Ai [],
-                                      const double Ax [], void *Symbolic, void **Numeric,
-                                      const double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO]);
+  SuiteSparse_long umfpack_dl_numeric(const SuiteSparse_long Ap[], const SuiteSparse_long Ai[],
+                                      const double Ax[], void* Symbolic, void** Numeric,
+                                      const double Control[UMFPACK_CONTROL],
+                                      double Info[UMFPACK_INFO]);
 
-  SuiteSparse_long umfpack_dl_solve(SuiteSparse_long sys, const SuiteSparse_long Ap [],
-                                    const SuiteSparse_long Ai [], const double Ax [],
-                                    double X [], const double B [], void *Numeric,
-                                    const double Control [UMFPACK_CONTROL], double Info [UMFPACK_INFO]);
+  SuiteSparse_long umfpack_dl_solve(SuiteSparse_long sys, const SuiteSparse_long Ap[],
+                                    const SuiteSparse_long Ai[], const double Ax[], double X[],
+                                    const double B[], void* Numeric,
+                                    const double Control[UMFPACK_CONTROL],
+                                    double Info[UMFPACK_INFO]);
 
-  void umfpack_dl_report_info(const double Control [UMFPACK_CONTROL],
-                              const double Info [UMFPACK_INFO]);
+  void umfpack_dl_report_info(const double Control[UMFPACK_CONTROL],
+                              const double Info[UMFPACK_INFO]);
 
-  void umfpack_dl_report_status(const double Control [UMFPACK_CONTROL],
-                                SuiteSparse_long status);
+  void umfpack_dl_report_status(const double Control[UMFPACK_CONTROL], SuiteSparse_long status);
 
-  void umfpack_dl_free_symbolic(void **Symbolic);
+  void umfpack_dl_free_symbolic(void** Symbolic);
 
-  void umfpack_dl_free_numeric(void **Numeric);
+  void umfpack_dl_free_numeric(void** Numeric);
 
-  SuiteSparse_long umfpack_dl_load_symbolic(void **Symbolic, char *filename);
+  SuiteSparse_long umfpack_dl_load_symbolic(void** Symbolic, char* filename);
 
-  SuiteSparse_long umfpack_dl_load_numeric(void **Numeric, char *filename);
+  SuiteSparse_long umfpack_dl_load_numeric(void** Numeric, char* filename);
 
-  SuiteSparse_long umfpack_dl_save_symbolic(void *Symbolic, char *filename);
+  SuiteSparse_long umfpack_dl_save_symbolic(void* Symbolic, char* filename);
 
-  SuiteSparse_long umfpack_dl_save_numeric(void *Numeric, char *filename);
+  SuiteSparse_long umfpack_dl_save_numeric(void* Numeric, char* filename);
 
 # ifdef __cplusplus
 } /* extern "C" */
diff --git a/mex/sources/gensylv/gensylv.cc b/mex/sources/gensylv/gensylv.cc
index ab45fb45464f28cc70243bddba6ee444f8fa2bef..d2f60a8283876454f397c0fef9f7ea7d2bd7538f 100644
--- a/mex/sources/gensylv/gensylv.cc
+++ b/mex/sources/gensylv/gensylv.cc
@@ -26,19 +26,17 @@
 #include "int_power.hh"
 
 void
-gen_sylv_solve(int order, int n, int m, int zero_cols,
-               const ConstVector &A, const ConstVector &B,
-               const ConstVector &C, Vector &X)
+gen_sylv_solve(int order, int n, int m, int zero_cols, const ConstVector& A, const ConstVector& B,
+               const ConstVector& C, Vector& X)
 {
   GeneralSylvester s(order, n, m, zero_cols, A, B, C, X, false);
   s.solve();
 }
 
-mxArray *
-gen_sylv_solve_and_check(int order, int n, int m, int zero_cols,
-                         const ConstVector &A, const ConstVector &B,
-                         const ConstVector &C, const ConstVector &D,
-                         Vector &X)
+mxArray*
+gen_sylv_solve_and_check(int order, int n, int m, int zero_cols, const ConstVector& A,
+                         const ConstVector& B, const ConstVector& C, const ConstVector& D,
+                         Vector& X)
 {
   GeneralSylvester s(order, n, m, zero_cols, A, B, C, X, true);
   s.solve();
@@ -46,10 +44,10 @@ gen_sylv_solve_and_check(int order, int n, int m, int zero_cols,
   return s.getParams().createStructArray();
 }
 
-extern "C" {
+extern "C"
+{
   void
-  mexFunction(int nlhs, mxArray *plhs[],
-              int nhrs, const mxArray *prhs[])
+  mexFunction(int nlhs, mxArray* plhs[], int nhrs, const mxArray* prhs[])
   {
     if (nhrs != 5 || nlhs > 2 || nlhs < 1)
       mexErrMsgTxt("Gensylv: Must have exactly 5 input args and either 1 or 2 output args.");
@@ -58,10 +56,10 @@ extern "C" {
       mexErrMsgTxt("First argument should be a numeric scalar");
 
     auto order = static_cast<int>(mxGetScalar(prhs[0]));
-    const mxArray *const A = prhs[1];
-    const mxArray *const B = prhs[2];
-    const mxArray *const C = prhs[3];
-    const mxArray *const D = prhs[4];
+    const mxArray* const A = prhs[1];
+    const mxArray* const B = prhs[2];
+    const mxArray* const C = prhs[3];
+    const mxArray* const D = prhs[4];
 
     if (!mxIsDouble(A) || mxIsComplex(A) || mxIsSparse(A))
       mexErrMsgTxt("Matrix A must be a real dense matrix.");
@@ -72,10 +70,10 @@ extern "C" {
     if (!mxIsDouble(D) || mxIsComplex(D) || mxIsSparse(D))
       mexErrMsgTxt("Matrix D must be a real dense matrix.");
 
-    const mwSize *const Adims = mxGetDimensions(A);
-    const mwSize *const Bdims = mxGetDimensions(B);
-    const mwSize *const Cdims = mxGetDimensions(C);
-    const mwSize *const Ddims = mxGetDimensions(D);
+    const mwSize* const Adims = mxGetDimensions(A);
+    const mwSize* const Bdims = mxGetDimensions(B);
+    const mwSize* const Cdims = mxGetDimensions(C);
+    const mwSize* const Ddims = mxGetDimensions(D);
 
     if (Adims[0] != Adims[1])
       mexErrMsgTxt("Matrix A must be a square matrix.");
@@ -93,10 +91,10 @@ extern "C" {
     auto n = static_cast<int>(Adims[0]);
     auto m = static_cast<int>(Cdims[0]);
     auto zero_cols = static_cast<int>(Bdims[0] - Bdims[1]);
-    mxArray *X = mxCreateDoubleMatrix(Ddims[0], Ddims[1], mxREAL);
+    mxArray* X = mxCreateDoubleMatrix(Ddims[0], Ddims[1], mxREAL);
     // copy D to X
-    ConstVector Avec{A}, Bvec{B}, Cvec{C}, Dvec{D};
-    Vector Xvec{X};
+    ConstVector Avec {A}, Bvec {B}, Cvec {C}, Dvec {D};
+    Vector Xvec {X};
     Xvec = Dvec;
     // solve (or solve and check)
     try
@@ -106,7 +104,7 @@ extern "C" {
         else if (nlhs == 2)
           plhs[1] = gen_sylv_solve_and_check(order, n, m, zero_cols, Avec, Bvec, Cvec, Dvec, Xvec);
       }
-    catch (const SylvException &e)
+    catch (const SylvException& e)
       {
         mexErrMsgTxt(e.getMessage().c_str());
       }
diff --git a/mex/sources/k_order_perturbation/k_order_perturbation.cc b/mex/sources/k_order_perturbation/k_order_perturbation.cc
index 68f194164822b951ba71706e1c9e854aaba1523e..7a4436eff95bf7d840da3b36949bf94445eb98e2 100644
--- a/mex/sources/k_order_perturbation/k_order_perturbation.cc
+++ b/mex/sources/k_order_perturbation/k_order_perturbation.cc
@@ -23,16 +23,16 @@
    outputs.
 */
 
-#include "dynamic_m.hh"
 #include "dynamic_dll.hh"
+#include "dynamic_m.hh"
 #include "k_ord_dynare.hh"
 
+#include "SylvException.hh"
 #include "approximation.hh"
-#include "exception.hh"
 #include "dynare_exception.hh"
+#include "exception.hh"
 #include "kord_exception.hh"
 #include "tl_exception.hh"
-#include "SylvException.hh"
 
 #include <algorithm>
 #include <cassert>
@@ -49,13 +49,13 @@ std::vector<std::string> g_fieldnames;
 /* Convert MATLAB Dynare endo and exo names cell array to a vector<string> array of
    string pointers. */
 std::vector<std::string>
-DynareMxArrayToString(const mxArray *mxFldp)
+DynareMxArrayToString(const mxArray* mxFldp)
 {
   assert(mxIsCell(mxFldp));
   std::vector<std::string> r;
   for (size_t i = 0; i < mxGetNumberOfElements(mxFldp); i++)
     {
-      const mxArray *cell_mx = mxGetCell(mxFldp, i);
+      const mxArray* cell_mx = mxGetCell(mxFldp, i);
       if (!(cell_mx && mxIsChar(cell_mx)))
         mexErrMsgTxt("Cell is not a character array");
       r.emplace_back(mxArrayToString(cell_mx));
@@ -65,90 +65,90 @@ DynareMxArrayToString(const mxArray *mxFldp)
 }
 
 void
-copy_derivatives(mxArray *destin, const Symmetry &sym, const FGSContainer &derivs, const char *fieldname)
+copy_derivatives(mxArray* destin, const Symmetry& sym, const FGSContainer& derivs,
+                 const char* fieldname)
 {
-  const FGSTensor &x = derivs.get(sym);
+  const FGSTensor& x = derivs.get(sym);
   auto x_unfolded = x.unfold();
   int n = x_unfolded->nrows();
   int m = x_unfolded->ncols();
-  mxArray *tmp = mxCreateDoubleMatrix(n, m, mxREAL);
-  std::copy_n(x_unfolded->getData().base(), n*m, mxGetPr(tmp));
+  mxArray* tmp = mxCreateDoubleMatrix(n, m, mxREAL);
+  std::copy_n(x_unfolded->getData().base(), n * m, mxGetPr(tmp));
   mxSetField(destin, 0, fieldname, tmp);
 }
 
-extern "C" {
+extern "C"
+{
 
   void
-  mexFunction(int nlhs, mxArray *plhs[],
-              int nrhs, const mxArray *prhs[])
+  mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
   {
     if (nrhs != 3 || nlhs < 1 || nlhs > 2)
       mexErrMsgTxt("Must have exactly 3 input parameters and takes 1 or 2 output parameters.");
 
     // Give explicit names to input arguments
-    const mxArray *dr_mx = prhs[0];
-    const mxArray *M_mx = prhs[1];
-    const mxArray *options_mx = prhs[2];
-
-    auto get_int_field = [](const mxArray *struct_mx, const std::string &fieldname)
-                         {
-                           mxArray *field_mx = mxGetField(struct_mx, 0, fieldname.c_str());
-                           if (!(field_mx && mxIsScalar(field_mx) && mxIsNumeric(field_mx)))
-                             mexErrMsgTxt(("Field `" + fieldname + "' should be a numeric scalar").c_str());
-                           return static_cast<int>(mxGetScalar(field_mx));
-                         };
+    const mxArray* dr_mx = prhs[0];
+    const mxArray* M_mx = prhs[1];
+    const mxArray* options_mx = prhs[2];
+
+    auto get_int_field = [](const mxArray* struct_mx, const std::string& fieldname) {
+      mxArray* field_mx = mxGetField(struct_mx, 0, fieldname.c_str());
+      if (!(field_mx && mxIsScalar(field_mx) && mxIsNumeric(field_mx)))
+        mexErrMsgTxt(("Field `" + fieldname + "' should be a numeric scalar").c_str());
+      return static_cast<int>(mxGetScalar(field_mx));
+    };
 
     // Extract various fields from options_
     const int kOrder = get_int_field(options_mx, "order");
     if (kOrder < 1)
       mexErrMsgTxt("options_.order must be at least 1");
 
-    const mxArray *use_dll_mx = mxGetField(options_mx, 0, "use_dll");
+    const mxArray* use_dll_mx = mxGetField(options_mx, 0, "use_dll");
     if (!(use_dll_mx && mxIsLogicalScalar(use_dll_mx)))
       mexErrMsgTxt("options_.use_dll should be a logical scalar");
     bool use_dll = static_cast<bool>(mxGetScalar(use_dll_mx));
 
-    double qz_criterium = 1+1e-6;
-    const mxArray *qz_criterium_mx = mxGetField(options_mx, 0, "qz_criterium");
+    double qz_criterium = 1 + 1e-6;
+    const mxArray* qz_criterium_mx = mxGetField(options_mx, 0, "qz_criterium");
     if (qz_criterium_mx && mxIsScalar(qz_criterium_mx) && mxIsNumeric(qz_criterium_mx))
       qz_criterium = mxGetScalar(qz_criterium_mx);
 
-    const mxArray *threads_mx = mxGetField(options_mx, 0, "threads");
+    const mxArray* threads_mx = mxGetField(options_mx, 0, "threads");
     if (!threads_mx)
       mexErrMsgTxt("Can't find field options_.threads");
-    const mxArray *num_threads_mx = mxGetField(threads_mx, 0, "k_order_perturbation");
+    const mxArray* num_threads_mx = mxGetField(threads_mx, 0, "k_order_perturbation");
     if (!(num_threads_mx && mxIsScalar(num_threads_mx) && mxIsNumeric(num_threads_mx)))
       mexErrMsgTxt("options_.threads.k_order_perturbation be a numeric scalar");
     int num_threads = static_cast<int>(mxGetScalar(num_threads_mx));
 
-    const mxArray *debug_mx = mxGetField(options_mx, 0, "debug");
+    const mxArray* debug_mx = mxGetField(options_mx, 0, "debug");
     if (!(debug_mx && mxIsLogicalScalar(debug_mx)))
       mexErrMsgTxt("options_.debug should be a logical scalar");
     bool debug = static_cast<bool>(mxGetScalar(debug_mx));
 
-    const mxArray *pruning_mx = mxGetField(options_mx, 0, "pruning");
+    const mxArray* pruning_mx = mxGetField(options_mx, 0, "pruning");
     if (!(pruning_mx && mxIsLogicalScalar(pruning_mx)))
       mexErrMsgTxt("options_.pruning should be a logical scalar");
     bool pruning = static_cast<bool>(mxGetScalar(pruning_mx));
 
     // Extract various fields from M_
-    const mxArray *fname_mx = mxGetField(M_mx, 0, "fname");
+    const mxArray* fname_mx = mxGetField(M_mx, 0, "fname");
     if (!(fname_mx && mxIsChar(fname_mx) && mxGetM(fname_mx) == 1))
       mexErrMsgTxt("M_.fname should be a character string");
-    std::string fname{mxArrayToString(fname_mx)};
+    std::string fname {mxArrayToString(fname_mx)};
 
-    const mxArray *params_mx = mxGetField(M_mx, 0, "params");
+    const mxArray* params_mx = mxGetField(M_mx, 0, "params");
     if (!(params_mx && mxIsDouble(params_mx) && !mxIsComplex(params_mx) && !mxIsSparse(params_mx)))
       mexErrMsgTxt("M_.params should be a real dense array");
-    Vector modParams{ConstVector{params_mx}};
+    Vector modParams {ConstVector {params_mx}};
     if (!modParams.isFinite())
       mexErrMsgTxt("M_.params contains NaN or Inf");
 
-    const mxArray *sigma_e_mx = mxGetField(M_mx, 0, "Sigma_e");
-    if (!(sigma_e_mx && mxIsDouble(sigma_e_mx) && !mxIsComplex(sigma_e_mx) && !mxIsSparse(sigma_e_mx)
-          && mxGetM(sigma_e_mx) == mxGetN(sigma_e_mx)))
+    const mxArray* sigma_e_mx = mxGetField(M_mx, 0, "Sigma_e");
+    if (!(sigma_e_mx && mxIsDouble(sigma_e_mx) && !mxIsComplex(sigma_e_mx)
+          && !mxIsSparse(sigma_e_mx) && mxGetM(sigma_e_mx) == mxGetN(sigma_e_mx)))
       mexErrMsgTxt("M_.Sigma_e should be a real dense square matrix");
-    TwoDMatrix vCov{ConstTwoDMatrix{sigma_e_mx}};
+    TwoDMatrix vCov {ConstTwoDMatrix {sigma_e_mx}};
     if (!vCov.isFinite())
       mexErrMsgTxt("M_.Sigma_e contains NaN or Inf");
 
@@ -161,63 +161,71 @@ extern "C" {
     const int nEndo = get_int_field(M_mx, "endo_nbr");
     const int nPar = get_int_field(M_mx, "param_nbr");
 
-    const mxArray *lead_lag_incidence_mx = mxGetField(M_mx, 0, "lead_lag_incidence");
+    const mxArray* lead_lag_incidence_mx = mxGetField(M_mx, 0, "lead_lag_incidence");
     if (!(lead_lag_incidence_mx && mxIsDouble(lead_lag_incidence_mx)
           && !mxIsComplex(lead_lag_incidence_mx) && !mxIsSparse(lead_lag_incidence_mx)
           && mxGetM(lead_lag_incidence_mx) == 3
           && mxGetN(lead_lag_incidence_mx) == static_cast<size_t>(nEndo)))
-      mexErrMsgTxt("M_.lead_lag_incidence should be a real dense matrix with 3 rows and M_.endo_nbr columns");
-    ConstTwoDMatrix llincidence{lead_lag_incidence_mx};
+      mexErrMsgTxt("M_.lead_lag_incidence should be a real dense matrix with 3 rows and "
+                   "M_.endo_nbr columns");
+    ConstTwoDMatrix llincidence {lead_lag_incidence_mx};
 
-    const mxArray *nnzderivatives_mx = mxGetField(M_mx, 0, "NNZDerivatives");
+    const mxArray* nnzderivatives_mx = mxGetField(M_mx, 0, "NNZDerivatives");
     if (!(nnzderivatives_mx && mxIsDouble(nnzderivatives_mx) && !mxIsComplex(nnzderivatives_mx)
           && !mxIsSparse(nnzderivatives_mx)))
       mexErrMsgTxt("M_.NNZDerivatives should be a double precision array");
-    ConstVector NNZD{nnzderivatives_mx};
-    if (NNZD.length() < kOrder || NNZD[kOrder-1] == -1)
-      mexErrMsgTxt("The derivatives were not computed for the required order. Make sure that you used the right order option inside the `stoch_simul' command");
-
-    const mxArray *endo_names_mx = mxGetField(M_mx, 0, "endo_names");
-    if (!(endo_names_mx && mxIsCell(endo_names_mx) && mxGetNumberOfElements(endo_names_mx) == static_cast<size_t>(nEndo)))
+    ConstVector NNZD {nnzderivatives_mx};
+    if (NNZD.length() < kOrder || NNZD[kOrder - 1] == -1)
+      mexErrMsgTxt("The derivatives were not computed for the required order. Make sure that you "
+                   "used the right order option inside the `stoch_simul' command");
+
+    const mxArray* endo_names_mx = mxGetField(M_mx, 0, "endo_names");
+    if (!(endo_names_mx && mxIsCell(endo_names_mx)
+          && mxGetNumberOfElements(endo_names_mx) == static_cast<size_t>(nEndo)))
       mexErrMsgTxt("M_.endo_names should be a cell array of M_.endo_nbr elements");
     std::vector<std::string> endoNames = DynareMxArrayToString(endo_names_mx);
 
-    const mxArray *exo_names_mx = mxGetField(M_mx, 0, "exo_names");
-    if (!(exo_names_mx && mxIsCell(exo_names_mx) && mxGetNumberOfElements(exo_names_mx) == static_cast<size_t>(nExog)))
+    const mxArray* exo_names_mx = mxGetField(M_mx, 0, "exo_names");
+    if (!(exo_names_mx && mxIsCell(exo_names_mx)
+          && mxGetNumberOfElements(exo_names_mx) == static_cast<size_t>(nExog)))
       mexErrMsgTxt("M_.exo_names should be a cell array of M_.exo_nbr elements");
     std::vector<std::string> exoNames = DynareMxArrayToString(exo_names_mx);
 
-    const mxArray *dynamic_tmp_nbr_mx = mxGetField(M_mx, 0, "dynamic_tmp_nbr");
+    const mxArray* dynamic_tmp_nbr_mx = mxGetField(M_mx, 0, "dynamic_tmp_nbr");
     if (!(dynamic_tmp_nbr_mx && mxIsDouble(dynamic_tmp_nbr_mx) && !mxIsComplex(dynamic_tmp_nbr_mx)
           && !mxIsSparse(dynamic_tmp_nbr_mx)
-          && mxGetNumberOfElements(dynamic_tmp_nbr_mx) >= static_cast<size_t>(kOrder+1)))
-      mexErrMsgTxt("M_.dynamic_tmp_nbr should be a real dense array with strictly more elements than the order of derivation");
-    int ntt = std::accumulate(mxGetPr(dynamic_tmp_nbr_mx), mxGetPr(dynamic_tmp_nbr_mx)+kOrder+1, 0);
+          && mxGetNumberOfElements(dynamic_tmp_nbr_mx) >= static_cast<size_t>(kOrder + 1)))
+      mexErrMsgTxt("M_.dynamic_tmp_nbr should be a real dense array with strictly more elements "
+                   "than the order of derivation");
+    int ntt
+        = std::accumulate(mxGetPr(dynamic_tmp_nbr_mx), mxGetPr(dynamic_tmp_nbr_mx) + kOrder + 1, 0);
 
     // Extract various fields from dr
-    const mxArray *ys_mx = mxGetField(dr_mx, 0, "ys"); // and not in order of dr.order_var
+    const mxArray* ys_mx = mxGetField(dr_mx, 0, "ys"); // and not in order of dr.order_var
     if (!(ys_mx && mxIsDouble(ys_mx) && !mxIsComplex(ys_mx) && !mxIsSparse(ys_mx)))
       mexErrMsgTxt("dr.ys should be a real dense array");
-    Vector ySteady{ConstVector{ys_mx}};
+    Vector ySteady {ConstVector {ys_mx}};
     if (!ySteady.isFinite())
       mexErrMsgTxt("dr.ys contains NaN or Inf");
 
-    const mxArray *order_var_mx = mxGetField(dr_mx, 0, "order_var");
-    if (!(order_var_mx && mxIsDouble(order_var_mx) && !mxIsComplex(order_var_mx) && !mxIsSparse(order_var_mx)
+    const mxArray* order_var_mx = mxGetField(dr_mx, 0, "order_var");
+    if (!(order_var_mx && mxIsDouble(order_var_mx) && !mxIsComplex(order_var_mx)
+          && !mxIsSparse(order_var_mx)
           && mxGetNumberOfElements(order_var_mx) == static_cast<size_t>(nEndo)))
       mexErrMsgTxt("dr.order_var should be a real dense array of M_.endo_nbr elements");
     std::vector<int> dr_order(nEndo);
-    std::transform(mxGetPr(order_var_mx), mxGetPr(order_var_mx)+nEndo, dr_order.begin(),
-                   [](double x) { return static_cast<int>(x)-1; });
+    std::transform(mxGetPr(order_var_mx), mxGetPr(order_var_mx) + nEndo, dr_order.begin(),
+                   [](double x) { return static_cast<int>(x) - 1; });
 
-    const int nSteps = 0; // Dynare++ solving steps, for time being default to 0 = deterministic steady state
+    const int nSteps
+        = 0; // Dynare++ solving steps, for time being default to 0 = deterministic steady state
 
     try
       {
         // Journal is not written on-disk, unless options_.debug = true (see #1735)
         Journal journal;
         if (debug)
-          journal = Journal{fname + ".jnl"};
+          journal = Journal {fname + ".jnl"};
 
         std::unique_ptr<DynamicModelAC> dynamicModelFile;
         if (use_dll)
@@ -226,15 +234,14 @@ extern "C" {
           dynamicModelFile = std::make_unique<DynamicModelMFile>(fname, ntt);
 
         // intiate tensor library
-        TLStatic::init(kOrder, nStat+2*nPred+3*nBoth+2*nForw+nExog);
+        TLStatic::init(kOrder, nStat + 2 * nPred + 3 * nBoth + 2 * nForw + nExog);
 
         // Set number of parallel threads
         sthread::detach_thread_group::max_parallel_threads = num_threads;
 
         // make KordpDynare object
-        KordpDynare dynare(endoNames, exoNames, nExog, nPar,
-                           ySteady, vCov, modParams, nStat, nPred, nForw, nBoth,
-                           NNZD, nSteps, kOrder, journal, std::move(dynamicModelFile),
+        KordpDynare dynare(endoNames, exoNames, nExog, nPar, ySteady, vCov, modParams, nStat, nPred,
+                           nForw, nBoth, NNZD, nSteps, kOrder, journal, std::move(dynamicModelFile),
                            dr_order, llincidence);
 
         // construct main K-order approximation class
@@ -242,53 +249,53 @@ extern "C" {
         // run stochastic steady
         app.walkStochSteady();
 
-        const FoldDecisionRule &fdr = app.getFoldDecisionRule();
+        const FoldDecisionRule& fdr = app.getFoldDecisionRule();
 
         // Add possibly missing field names
         for (int i = static_cast<int>(g_fieldnames.size()); i <= kOrder; i++)
           g_fieldnames.emplace_back("g_" + std::to_string(i));
         // Create structure for storing derivatives in Dynare++ format
-        const char *g_fieldnames_c[kOrder+1];
+        const char* g_fieldnames_c[kOrder + 1];
         for (int i = 0; i <= kOrder; i++)
           g_fieldnames_c[i] = g_fieldnames[i].c_str();
-        
+
         if (pruning)
           {
-            std::vector<std::string> g_fieldnames_pruning(g_fieldnames);   
+            std::vector<std::string> g_fieldnames_pruning(g_fieldnames);
             g_fieldnames_pruning.emplace_back("pruning");
-            const char *g_fieldnames_pruning_c[kOrder+2];
-            std::copy_n(g_fieldnames_c, kOrder+1, g_fieldnames_pruning_c);
-            g_fieldnames_pruning_c[kOrder+1] = g_fieldnames_pruning.back().c_str();
-            plhs[0] = mxCreateStructMatrix(1, 1, kOrder+2, g_fieldnames_pruning_c);
+            const char* g_fieldnames_pruning_c[kOrder + 2];
+            std::copy_n(g_fieldnames_c, kOrder + 1, g_fieldnames_pruning_c);
+            g_fieldnames_pruning_c[kOrder + 1] = g_fieldnames_pruning.back().c_str();
+            plhs[0] = mxCreateStructMatrix(1, 1, kOrder + 2, g_fieldnames_pruning_c);
           }
         else
-            plhs[0] = mxCreateStructMatrix(1, 1, kOrder+1, g_fieldnames_c);
+          plhs[0] = mxCreateStructMatrix(1, 1, kOrder + 1, g_fieldnames_c);
 
         // Fill that structure
         for (int i = 0; i <= kOrder; i++)
           {
-            const FFSTensor &t = fdr.get(Symmetry{i});
-            mxArray *tmp = mxCreateDoubleMatrix(t.nrows(), t.ncols(), mxREAL);
-            const ConstVector &vec = t.getData();
+            const FFSTensor& t = fdr.get(Symmetry {i});
+            mxArray* tmp = mxCreateDoubleMatrix(t.nrows(), t.ncols(), mxREAL);
+            const ConstVector& vec = t.getData();
             assert(vec.skip() == 1);
             std::copy_n(vec.base(), vec.length(), mxGetPr(tmp));
             mxSetField(plhs[0], 0, g_fieldnames_c[i], tmp);
           }
 
-        // Filling the output elements for pruning 
+        // Filling the output elements for pruning
         if (pruning)
           {
-            const UnfoldDecisionRule &udr_pruning = app.getUnfoldDecisionRulePruning();
+            const UnfoldDecisionRule& udr_pruning = app.getUnfoldDecisionRulePruning();
 
-            mxArray *dr_pruning = mxCreateStructMatrix(1, 1, kOrder+1, g_fieldnames_c);
+            mxArray* dr_pruning = mxCreateStructMatrix(1, 1, kOrder + 1, g_fieldnames_c);
             mxSetField(plhs[0], 0, "pruning", dr_pruning);
 
             // Fill that structure
             for (int i = 0; i <= kOrder; i++)
               {
-                const UFSTensor &t = udr_pruning.get(Symmetry{i});
-                mxArray *tmp = mxCreateDoubleMatrix(t.nrows(), t.ncols(), mxREAL);
-                const ConstVector &vec = t.getData();
+                const UFSTensor& t = udr_pruning.get(Symmetry {i});
+                mxArray* tmp = mxCreateDoubleMatrix(t.nrows(), t.ncols(), mxREAL);
+                const ConstVector& vec = t.getData();
                 assert(vec.skip() == 1);
                 std::copy_n(vec.base(), vec.length(), mxGetPr(tmp));
                 mxSetField(dr_pruning, 0, g_fieldnames_c[i], tmp);
@@ -300,55 +307,58 @@ extern "C" {
             /* Return as 3rd argument a struct containing derivatives in Dynare
                format (unfolded matrices, without Taylor coefficient) up to 3rd
                order */
-            const FGSContainer &derivs = app.get_rule_ders();
+            const FGSContainer& derivs = app.get_rule_ders();
 
             size_t nfields = (kOrder == 1 ? 2 : (kOrder == 2 ? 6 : 12));
-            const char *c_fieldnames[] = { "gy", "gu", "gyy", "gyu", "guu", "gss",
-                                           "gyyy", "gyyu", "gyuu", "guuu", "gyss", "guss" };
+            const char* c_fieldnames[] = {"gy",   "gu",   "gyy",  "gyu",  "guu",  "gss",
+                                          "gyyy", "gyyu", "gyuu", "guuu", "gyss", "guss"};
             plhs[1] = mxCreateStructMatrix(1, 1, nfields, c_fieldnames);
 
-            copy_derivatives(plhs[1], Symmetry{1, 0, 0, 0}, derivs, "gy");
-            copy_derivatives(plhs[1], Symmetry{0, 1, 0, 0}, derivs, "gu");
+            copy_derivatives(plhs[1], Symmetry {1, 0, 0, 0}, derivs, "gy");
+            copy_derivatives(plhs[1], Symmetry {0, 1, 0, 0}, derivs, "gu");
             if (kOrder >= 2)
               {
-                copy_derivatives(plhs[1], Symmetry{2, 0, 0, 0}, derivs, "gyy");
-                copy_derivatives(plhs[1], Symmetry{0, 2, 0, 0}, derivs, "guu");
-                copy_derivatives(plhs[1], Symmetry{1, 1, 0, 0}, derivs, "gyu");
-                copy_derivatives(plhs[1], Symmetry{0, 0, 0, 2}, derivs, "gss");
+                copy_derivatives(plhs[1], Symmetry {2, 0, 0, 0}, derivs, "gyy");
+                copy_derivatives(plhs[1], Symmetry {0, 2, 0, 0}, derivs, "guu");
+                copy_derivatives(plhs[1], Symmetry {1, 1, 0, 0}, derivs, "gyu");
+                copy_derivatives(plhs[1], Symmetry {0, 0, 0, 2}, derivs, "gss");
               }
             if (kOrder >= 3)
               {
-                copy_derivatives(plhs[1], Symmetry{3, 0, 0, 0}, derivs, "gyyy");
-                copy_derivatives(plhs[1], Symmetry{0, 3, 0, 0}, derivs, "guuu");
-                copy_derivatives(plhs[1], Symmetry{2, 1, 0, 0}, derivs, "gyyu");
-                copy_derivatives(plhs[1], Symmetry{1, 2, 0, 0}, derivs, "gyuu");
-                copy_derivatives(plhs[1], Symmetry{1, 0, 0, 2}, derivs, "gyss");
-                copy_derivatives(plhs[1], Symmetry{0, 1, 0, 2}, derivs, "guss");
+                copy_derivatives(plhs[1], Symmetry {3, 0, 0, 0}, derivs, "gyyy");
+                copy_derivatives(plhs[1], Symmetry {0, 3, 0, 0}, derivs, "guuu");
+                copy_derivatives(plhs[1], Symmetry {2, 1, 0, 0}, derivs, "gyyu");
+                copy_derivatives(plhs[1], Symmetry {1, 2, 0, 0}, derivs, "gyuu");
+                copy_derivatives(plhs[1], Symmetry {1, 0, 0, 2}, derivs, "gyss");
+                copy_derivatives(plhs[1], Symmetry {0, 1, 0, 2}, derivs, "guss");
               }
           }
       }
-    catch (const KordException &e)
+    catch (const KordException& e)
       {
         e.print();
-        mexErrMsgTxt(("dynare:k_order_perturbation: Caught Kord exception: " + e.get_message()).c_str());
+        mexErrMsgTxt(
+            ("dynare:k_order_perturbation: Caught Kord exception: " + e.get_message()).c_str());
       }
-    catch (const TLException &e)
+    catch (const TLException& e)
       {
         e.print();
         mexErrMsgTxt("dynare:k_order_perturbation: Caught TL exception");
       }
-    catch (SylvException &e)
+    catch (SylvException& e)
       {
         e.printMessage();
         mexErrMsgTxt("dynare:k_order_perturbation: Caught Sylv exception");
       }
-    catch (const DynareException &e)
+    catch (const DynareException& e)
       {
-        mexErrMsgTxt(("dynare:k_order_perturbation: Caught KordDynare exception: " + e.message()).c_str());
+        mexErrMsgTxt(
+            ("dynare:k_order_perturbation: Caught KordDynare exception: " + e.message()).c_str());
       }
-    catch (const ogu::Exception &e)
+    catch (const ogu::Exception& e)
       {
-        mexErrMsgTxt(("dynare:k_order_perturbation: Caught general exception: " + e.message()).c_str());
+        mexErrMsgTxt(
+            ("dynare:k_order_perturbation: Caught general exception: " + e.message()).c_str());
       }
   } // end of mexFunction()
 } // end of extern C
diff --git a/mex/sources/k_order_perturbation/tests/k_order_test_main.cc b/mex/sources/k_order_perturbation/tests/k_order_test_main.cc
index 4541baf79b0261fedb07c662c3d759ce34d8755f..2c8612f79e1d334371f545b2ebe87593a5e1d1fe 100644
--- a/mex/sources/k_order_perturbation/tests/k_order_test_main.cc
+++ b/mex/sources/k_order_perturbation/tests/k_order_test_main.cc
@@ -24,38 +24,32 @@
  * The main has been derived from mxFunction used for K-Order DLL
  ***************************************/
 
-//#include "stdafx.h"
-#include "k_ord_dynare.h"
+// #include "stdafx.h"
 #include "dynamic_dll.h"
+#include "k_ord_dynare.h"
 
 int
-main(int argc, char *argv[])
+main(int argc, char* argv[])
 {
 
-  double qz_criterium = 1+1e-6;
+  double qz_criterium = 1 + 1e-6;
   const int check_flag = 0;
-  const char *fName = "./fs2000k"; //mxArrayToString(mFname);
-  const char *dfExt = ".mexa64"; //Dynamic file extension, e.g.".dll";
+  const char* fName = "./fs2000k"; // mxArrayToString(mFname);
+  const char* dfExt = ".mexa64";   // Dynamic file extension, e.g.".dll";
 
 #ifdef DEBUG
   mexPrintf("k_order_perturbation: check_flag = %d ,  fName = %s .\n", check_flag, fName);
 #endif
   int kOrder = 2;
   int npar = 7; //(int)mxGetM(mxFldp);
-  double dparams[7] = { 0.3300,
-                        0.9900,
-                        0.0030,
-                        1.0110,
-                        0.7000,
-                        0.7870,
-                        0.0200};
-  Vector *modParams = new Vector(dparams, npar);
+  double dparams[7] = {0.3300, 0.9900, 0.0030, 1.0110, 0.7000, 0.7870, 0.0200};
+  Vector* modParams = new Vector(dparams, npar);
 
 #ifdef DEBUG
   mexPrintf("k_ord_perturbation: nParams=%d .\n", npar);
   for (int i = 0; i < npar; i++)
     {
-      mexPrintf("k_ord_perturbation: dParams[%d]= %g.\n", i, dparams+i*(sizeof(double)));
+      mexPrintf("k_ord_perturbation: dParams[%d]= %g.\n", i, dparams + i * (sizeof(double)));
     }
   for (int i = 0; i < npar; i++)
     {
@@ -64,102 +58,86 @@ main(int argc, char *argv[])
 
 #endif
 
-  double d2Dparams[4] = { //(double *) mxGetData(mxFldp);
-                         0.1960e-3, 0.0,
-                         0.0, 0.0250e-3
-  };
+  double d2Dparams[4] = {//(double *) mxGetData(mxFldp);
+                         0.1960e-3, 0.0, 0.0, 0.0250e-3};
   npar = 2; //(int)mxGetN(mxFldp);
-  TwoDMatrix *vCov = new TwoDMatrix(npar, npar, (d2Dparams));
-  double dYSparams[16] = { // 27 mxGetData(mxFldp);
-                          //	1.0110,  2.2582,  5.8012,  0.5808,
-                          1.0110, 2.2582, 0.4477, 1.0000,
-                          4.5959, 1.0212, 5.8012, 0.8494,
-                          0.1872, 0.8604, 1.0030, 1.0080,
-                          0.5808, 1.0030, 2.2582, 0.4477
-                          //,  1.0110,  2.2582,  0.4477,  1.0000,	0.1872,  2.2582,  0.4477
+  TwoDMatrix* vCov = new TwoDMatrix(npar, npar, (d2Dparams));
+  double dYSparams[16] = {
+      // 27 mxGetData(mxFldp);
+      //	1.0110,  2.2582,  5.8012,  0.5808,
+      1.0110, 2.2582, 0.4477, 1.0000, 4.5959, 1.0212, 5.8012, 0.8494, 0.1872,
+      0.8604, 1.0030, 1.0080, 0.5808, 1.0030, 2.2582, 0.4477
+      //,  1.0110,  2.2582,  0.4477,  1.0000,	0.1872,  2.2582,  0.4477
   };
-  const int nSteady = 16; //27 //31;//29, 16 (int)mxGetM(mxFldp);
-  Vector *ySteady = new Vector(dYSparams, nSteady);
+  const int nSteady = 16; // 27 //31;//29, 16 (int)mxGetM(mxFldp);
+  Vector* ySteady = new Vector(dYSparams, nSteady);
 
-  double nnzd[3] = { 77, 217, 0};
-  const Vector *NNZD = new Vector(nnzd, 3);
+  double nnzd[3] = {77, 217, 0};
+  const Vector* NNZD = new Vector(nnzd, 3);
 
-  //mxFldp = mxGetField(dr, 0,"nstatic" );
+  // mxFldp = mxGetField(dr, 0,"nstatic" );
   const int nStat = 7; //(int)mxGetScalar(mxFldp);
   //	mxFldp = mxGetField(dr, 0,"npred" );
-  const int nPred = 2; //6 - nBoth (int)mxGetScalar(mxFldp);
-  //mxFldp = mxGetField(dr, 0,"nspred" );
+  const int nPred = 2; // 6 - nBoth (int)mxGetScalar(mxFldp);
+  // mxFldp = mxGetField(dr, 0,"nspred" );
   const int nsPred = 4; //(int)mxGetScalar(mxFldp);
-  //mxFldp = mxGetField(dr, 0,"nboth" );
+  // mxFldp = mxGetField(dr, 0,"nboth" );
   const int nBoth = 2; // (int)mxGetScalar(mxFldp);
-  //mxFldp = mxGetField(dr, 0,"nfwrd" );
+  // mxFldp = mxGetField(dr, 0,"nfwrd" );
   const int nForw = 5; // 3 (int)mxGetScalar(mxFldp);
-  //mxFldp = mxGetField(dr, 0,"nsfwrd" );
+  // mxFldp = mxGetField(dr, 0,"nsfwrd" );
   const int nsForw = 7; //(int)mxGetScalar(mxFldp);
 
-  //mxFldp = mxGetField(M_, 0,"exo_nbr" );
+  // mxFldp = mxGetField(M_, 0,"exo_nbr" );
   const int nExog = 2; // (int)mxGetScalar(mxFldp);
-  //mxFldp = mxGetField(M_, 0,"endo_nbr" );
-  const int nEndo = 16; //16(int)mxGetScalar(mxFldp);
-  //mxFldp = mxGetField(M_, 0,"param_nbr" );
+  // mxFldp = mxGetField(M_, 0,"endo_nbr" );
+  const int nEndo = 16; // 16(int)mxGetScalar(mxFldp);
+  // mxFldp = mxGetField(M_, 0,"param_nbr" );
   const int nPar = 7; //(int)mxGetScalar(mxFldp);
   // it_ should be set to M_.maximum_lag
-  //mxFldp = mxGetField(M_, 0,"maximum_lag" );
+  // mxFldp = mxGetField(M_, 0,"maximum_lag" );
   const int nMax_lag = 1; //(int)mxGetScalar(mxFldp);
 
   int var_order[] //[18]
-    = {
-       5, 6, 8, 10, 11, 12, 14, 7, 13, 1, 2, 3, 4, 9, 15, 16
-       //			 5,  6,  8, 10, 11, 12, 16,  7, 13, 14, 15,  1,  2,  3, 4,  9, 17, 18
-  };
-  //Vector * varOrder =  new Vector(var_order, nEndo);
-  vector<int> *var_order_vp = new vector<int>(nEndo); //nEndo));
+      = {
+          5, 6, 8, 10, 11, 12, 14, 7, 13,
+          1, 2, 3, 4,  9,  15, 16
+          //			 5,  6,  8, 10, 11, 12, 16,  7, 13, 14, 15,  1,  2,  3, 4,  9, 17,
+          // 18
+      };
+  // Vector * varOrder =  new Vector(var_order, nEndo);
+  vector<int>* var_order_vp = new vector<int>(nEndo); // nEndo));
   for (int v = 0; v < nEndo; v++)
     (*var_order_vp)[v] = var_order[v];
 
   const double ll_incidence[] //[3][18]
-    = {
-       1, 5, 21,
-       2, 6, 22,
-       0, 7, 23,
-       0, 8, 24,
-       0, 9, 0,
-       0, 10, 0,
-       3, 11, 0,
-       0, 12, 0,
-       0, 13, 25,
-       0, 14, 0,
-       0, 15, 0,
-       0, 16, 0,
-       4, 17, 0,
-       0, 18, 0,
-       0, 19, 26,
-       0, 20, 27
-  };
-  TwoDMatrix *llincidence = new TwoDMatrix(3, nEndo, ll_incidence);
+      = {1, 5,  21, 2, 6,  22, 0, 7,  23, 0, 8,  24, 0, 9,  0, 0, 10, 0, 3, 11, 0,  0, 12, 0,
+         0, 13, 25, 0, 14, 0,  0, 15, 0,  0, 16, 0,  4, 17, 0, 0, 18, 0, 0, 19, 26, 0, 20, 27};
+  TwoDMatrix* llincidence = new TwoDMatrix(3, nEndo, ll_incidence);
 
-  const int jcols = nExog+nEndo+nsPred+nsForw; // Num of Jacobian columns
+  const int jcols = nExog + nEndo + nsPred + nsForw; // Num of Jacobian columns
 #ifdef DEBUG
   mexPrintf("k_order_perturbation: jcols= %d .\n", jcols);
 #endif
-  //mxFldp= mxGetField(M_, 0,"endo_names" );
-  const int nendo = 16; //16(int)mxGetM(mxFldp);
+  // mxFldp= mxGetField(M_, 0,"endo_names" );
+  const int nendo = 16;    // 16(int)mxGetM(mxFldp);
   const int widthEndo = 6; // (int)mxGetN(mxFldp);
-  const char *cNamesCharStr = "mPceWRkdnlggydPc          yp A22          __              oo              bb              ss    ";
+  const char* cNamesCharStr = "mPceWRkdnlggydPc          yp A22          __              oo        "
+                              "      bb              ss    ";
   //   const char**  endoNamesMX= DynareMxArrayToString( mxFldp,nendo,widthEndo);
-  const char **endoNamesMX = DynareMxArrayToString(cNamesCharStr, nendo, widthEndo);
+  const char** endoNamesMX = DynareMxArrayToString(cNamesCharStr, nendo, widthEndo);
 #ifdef DEBUG
   for (int i = 0; i < nEndo; i++)
     {
       mexPrintf("k_ord_perturbation: EndoNameList[%d][0]= %s.\n", i, endoNamesMX[i]);
     }
 #endif
-  //mxFldp      = mxGetField(M_, 0,"exo_names" );
-  const int nexo = 2; //(int)mxGetM(mxFldp);
+  // mxFldp      = mxGetField(M_, 0,"exo_names" );
+  const int nexo = 2;      //(int)mxGetM(mxFldp);
   const int widthExog = 3; //(int)mxGetN(mxFldp);
   //        const char**  exoNamesMX= DynareMxArrayToString( mxFldp,nexo,widthExog);
-  const char *cExoNamesCharStr = "ee__am";
-  const char **exoNamesMX = DynareMxArrayToString(cExoNamesCharStr, nexo, widthExog);
+  const char* cExoNamesCharStr = "ee__am";
+  const char** exoNamesMX = DynareMxArrayToString(cExoNamesCharStr, nexo, widthExog);
 #ifdef DEBUG
   for (int i = 0; i < nexo; i++)
     {
@@ -193,15 +171,16 @@ main(int argc, char *argv[])
   /* Fetch time index */
   //		int it_ = (int) mxGetScalar(prhs[3]) - 1;
 
-  const int nSteps = 0; // Dynare++ solving steps, for time being default to 0 = deterministic steady state
-  const double sstol = 1.e-13; //NL solver tolerance from
+  const int nSteps
+      = 0; // Dynare++ solving steps, for time being default to 0 = deterministic steady state
+  const double sstol = 1.e-13; // NL solver tolerance from
 
-  THREAD_GROUP::max_parallel_threads = 1; //2 params.num_threads;
+  THREAD_GROUP::max_parallel_threads = 1; // 2 params.num_threads;
 
   try
     {
       // make journal name and journal
-      std::string jName(fName); //params.basename);
+      std::string jName(fName); // params.basename);
       jName += ".jnl";
       Journal journal(jName.c_str());
 
@@ -209,7 +188,7 @@ main(int argc, char *argv[])
       mexPrintf("k_order_perturbation: Call tls init\n");
 #endif
 
-      tls.init(kOrder, (nStat+2*nPred+3*nBoth+2*nForw+nExog));
+      tls.init(kOrder, (nStat + 2 * nPred + 3 * nBoth + 2 * nForw + nExog));
 
 #ifdef DEBUG
       mexPrintf("k_order_perturbation: Calling dynamicDLL constructor.\n");
@@ -221,8 +200,8 @@ main(int argc, char *argv[])
 #endif
       // make KordpDynare object
       KordpDynare dynare(endoNamesMX, nEndo, exoNamesMX, nExog, nPar, // paramNames,
-                         ySteady, vCov, modParams, nStat, nPred, nForw, nBoth,
-                         jcols, NNZD, nSteps, kOrder, journal, dynamicDLL, sstol, var_order_vp, //var_order
+                         ySteady, vCov, modParams, nStat, nPred, nForw, nBoth, jcols, NNZD, nSteps,
+                         kOrder, journal, dynamicDLL, sstol, var_order_vp, // var_order
                          llincidence, qz_criterium);
 #ifdef DEBUG
       mexPrintf("k_order_perturbation: Call Approximation constructor \n");
@@ -237,7 +216,7 @@ main(int argc, char *argv[])
       // open mat file
       std::string matfile(fName); //(params.basename);
       matfile += ".mat";
-      FILE *matfd = NULL;
+      FILE* matfd = NULL;
       if (NULL == (matfd = fopen(matfile.c_str(), "wb")))
         {
           fprintf(stderr, "Couldn't open %s for writing.\n", matfile.c_str());
@@ -247,12 +226,12 @@ main(int argc, char *argv[])
 #ifdef DEBUG
       mexPrintf("k_order_perturbation: Filling Mat file outputs.\n");
 #endif
-      std::string ss_matrix_name(fName); //params.prefix);
+      std::string ss_matrix_name(fName); // params.prefix);
       ss_matrix_name += "_steady_states";
       ConstTwoDMatrix(app.getSS()).writeMat4(matfd, ss_matrix_name.c_str());
 
       // write the folded decision rule to the Mat-4 file
-      app.getFoldDecisionRule().writeMat4(matfd, fName); //params.prefix);
+      app.getFoldDecisionRule().writeMat4(matfd, fName); // params.prefix);
 
       fclose(matfd);
 
@@ -261,8 +240,7 @@ main(int argc, char *argv[])
 #ifdef DEBUG
       app.getFoldDecisionRule().print();
       mexPrintf("k_order_perturbation: Map print: \n");
-      for (map<string, ConstTwoDMatrix>::const_iterator cit = mm.begin();
-           cit != mm.end(); ++cit)
+      for (map<string, ConstTwoDMatrix>::const_iterator cit = mm.begin(); cit != mm.end(); ++cit)
         {
           mexPrintf("k_order_perturbation: Map print: string: %s , g:\n", (*cit).first.c_str());
           (*cit).second.print();
@@ -270,33 +248,33 @@ main(int argc, char *argv[])
 #endif
 
       // get latest ysteady
-      double *dYsteady = (dynare.getSteady().base());
-      ySteady = (Vector *) (&dynare.getSteady());
+      double* dYsteady = (dynare.getSteady().base());
+      ySteady = (Vector*)(&dynare.getSteady());
     }
-  catch (const KordException &e)
+  catch (const KordException& e)
     {
       printf("Caugth Kord exception: ");
       e.print();
       return 1; // e.code();
     }
-  catch (const TLException &e)
+  catch (const TLException& e)
     {
       printf("Caugth TL exception: ");
       e.print();
       return 2; // 255;
     }
-  catch (SylvException &e)
+  catch (SylvException& e)
     {
       printf("Caught Sylv exception: ");
       e.printMessage();
       return 3; // 255;
     }
-  catch (const DynareException &e)
+  catch (const DynareException& e)
     {
       printf("Caught KordpDynare exception: %s\n", e.message());
       return 4; // 255;
     }
-  catch (const ogu::Exception &e)
+  catch (const ogu::Exception& e)
     {
       printf("Caught ogu::Exception: ");
       e.print();
@@ -307,8 +285,8 @@ main(int argc, char *argv[])
   const int nrhs = 5;
   const int nlhs = 2;
 
-  mxArray *prhs[nrhs];
-  mxArray *plhs[nlhs];
+  mxArray* prhs[nrhs];
+  mxArray* plhs[nlhs];
 
 #ifdef DEBUG
   mexPrintf("k_order_perturbation: Filling MATLAB outputs.\n");
diff --git a/mex/sources/k_order_welfare/approximation_welfare.cc b/mex/sources/k_order_welfare/approximation_welfare.cc
index ccd82854cf1bfc39b34fcf7aaf6782eaec71d8b3..c33855ff8ee0230b89d2f28fcc9985dd3cfa13e6 100644
--- a/mex/sources/k_order_welfare/approximation_welfare.cc
+++ b/mex/sources/k_order_welfare/approximation_welfare.cc
@@ -20,11 +20,16 @@
 
 #include <utility>
 
-#include "kord_exception.hh"
 #include "approximation_welfare.hh"
+#include "kord_exception.hh"
 
-ApproximationWelfare::ApproximationWelfare(KordwDynare &w, double discount_factor_arg, const FGSContainer &rule_ders_arg, const FGSContainer &rule_ders_s_arg, Journal &j)
-  : welfare{w}, discount_factor(discount_factor_arg), nvs{welfare.getModel().nys(), welfare.getModel().nexog(), welfare.getModel().nexog(), 1}, journal{j}
+ApproximationWelfare::ApproximationWelfare(KordwDynare& w, double discount_factor_arg,
+                                           const FGSContainer& rule_ders_arg,
+                                           const FGSContainer& rule_ders_s_arg, Journal& j) :
+    welfare {w},
+    discount_factor(discount_factor_arg), nvs {welfare.getModel().nys(), welfare.getModel().nexog(),
+                                               welfare.getModel().nexog(), 1},
+    journal {j}
 {
   rule_ders = std::make_unique<FGSContainer>(rule_ders_arg);
   rule_ders_s = std::make_unique<FGSContainer>(rule_ders_s_arg);
@@ -38,25 +43,32 @@ void
 ApproximationWelfare::approxAtSteady()
 {
   welfare.calcDerivativesAtSteady();
-  KOrderWelfare korderwel(welfare.getModel().nstat(), welfare.getModel().npred(), welfare.getModel().nboth(), welfare.getModel().nforw(), welfare.getModel().nexog(), welfare.getModel().order(), discount_factor, welfare.getPlannerObjDerivatives(), get_rule_ders(), get_rule_ders_s(), welfare.getModel().getVcov(), journal); 
+  KOrderWelfare korderwel(welfare.getModel().nstat(), welfare.getModel().npred(),
+                          welfare.getModel().nboth(), welfare.getModel().nforw(),
+                          welfare.getModel().nexog(), welfare.getModel().order(), discount_factor,
+                          welfare.getPlannerObjDerivatives(), get_rule_ders(), get_rule_ders_s(),
+                          welfare.getModel().getVcov(), journal);
   for (int k = 1; k <= welfare.getModel().order(); k++)
     korderwel.performStep<Storage::fold>(k);
   saveRuleDerivs(korderwel.getFoldW());
 
   // construct the resulting decision rule
-  cond_fdr = std::make_unique<FoldDecisionRule>(*cond_ders, welfare.getModel().nys(), welfare.getModel().nexog(), welfare.getModel().getSteady());
+  cond_fdr = std::make_unique<FoldDecisionRule>(*cond_ders, welfare.getModel().nys(),
+                                                welfare.getModel().nexog(),
+                                                welfare.getModel().getSteady());
 }
 
-const FoldDecisionRule &
+const FoldDecisionRule&
 ApproximationWelfare::getFoldCondWel() const
 {
-  KORD_RAISE_IF(!cond_fdr,
-                "Folded decision rule has not been created in ApproximationWelfare::getFoldCondWel");
+  KORD_RAISE_IF(
+      !cond_fdr,
+      "Folded decision rule has not been created in ApproximationWelfare::getFoldCondWel");
   return *cond_fdr;
 }
 
 void
-ApproximationWelfare::saveRuleDerivs(const FGSContainer &W)
+ApproximationWelfare::saveRuleDerivs(const FGSContainer& W)
 {
   cond_ders = std::make_unique<FGSContainer>(W);
 }
\ No newline at end of file
diff --git a/mex/sources/k_order_welfare/approximation_welfare.hh b/mex/sources/k_order_welfare/approximation_welfare.hh
index 9c22eae259edc15b4350fb4afcd5ad54543111f2..76d8d27b0bb232a874009d065c09bde60fd2839b 100644
--- a/mex/sources/k_order_welfare/approximation_welfare.hh
+++ b/mex/sources/k_order_welfare/approximation_welfare.hh
@@ -20,50 +20,52 @@
 #ifndef APPROXIMATION_WELFARE_H
 #define APPROXIMATION_WELFARE_H
 
-#include "k_ord_objective.hh"
 #include "journal.hh"
+#include "k_ord_objective.hh"
 
 #include <memory>
 
 class ApproximationWelfare
 {
-  KordwDynare &welfare;
+  KordwDynare& welfare;
   double discount_factor;
   std::unique_ptr<FGSContainer> rule_ders;
   std::unique_ptr<FGSContainer> rule_ders_s;
   std::unique_ptr<FGSContainer> cond_ders;
   std::unique_ptr<FoldDecisionRule> cond_fdr;
   IntSequence nvs;
-  Journal &journal;
+  Journal& journal;
+
 public:
-  ApproximationWelfare(KordwDynare &w, double discount_factor, const FGSContainer &rule_ders, const FGSContainer &rule_ders_s, Journal &j);
+  ApproximationWelfare(KordwDynare& w, double discount_factor, const FGSContainer& rule_ders,
+                       const FGSContainer& rule_ders_s, Journal& j);
 
-  const KordwDynare &
+  const KordwDynare&
   getWelfare() const
   {
     return welfare;
   }
-  const FGSContainer &
+  const FGSContainer&
   get_rule_ders() const
   {
     return *rule_ders;
   }
-  const FGSContainer &
+  const FGSContainer&
   get_rule_ders_s() const
   {
     return *rule_ders_s;
   }
-  const FGSContainer &
+  const FGSContainer&
   get_cond_ders() const
   {
     return *cond_ders;
   }
-  const FoldDecisionRule & getFoldCondWel() const;
+  const FoldDecisionRule& getFoldCondWel() const;
 
   void approxAtSteady();
 
 protected:
-  void saveRuleDerivs(const FGSContainer &W);
+  void saveRuleDerivs(const FGSContainer& W);
 };
 
 #endif
diff --git a/mex/sources/k_order_welfare/k_ord_objective.cc b/mex/sources/k_order_welfare/k_ord_objective.cc
index e54720c5515c268f399b8b36cde74820640bd25f..e432767b0d0726daf4096ac7cbb1b8fc54d8db47 100644
--- a/mex/sources/k_order_welfare/k_ord_objective.cc
+++ b/mex/sources/k_order_welfare/k_ord_objective.cc
@@ -20,11 +20,15 @@
 #include "k_ord_objective.hh"
 #include "objective_abstract_class.hh"
 
-#include <utility>
 #include <cassert>
+#include <utility>
 
-KordwDynare::KordwDynare(KordpDynare &m, ConstVector &NNZD_arg, Journal &jr, Vector &inParams, std::unique_ptr<ObjectiveAC> objectiveFile_arg, const std::vector<int> &dr_order) :
-  model{m}, NNZD{NNZD_arg}, journal{jr}, params{inParams}, resid(1), ud{1}, objectiveFile{std::move(objectiveFile_arg)}
+KordwDynare::KordwDynare(KordpDynare& m, ConstVector& NNZD_arg, Journal& jr, Vector& inParams,
+                         std::unique_ptr<ObjectiveAC> objectiveFile_arg,
+                         const std::vector<int>& dr_order) :
+    model {m},
+    NNZD {NNZD_arg}, journal {jr}, params {inParams},
+    resid(1), ud {1}, objectiveFile {std::move(objectiveFile_arg)}
 {
   dynppToDyn = dr_order;
   dynToDynpp.resize(model.ny());
@@ -38,14 +42,14 @@ KordwDynare::calcDerivativesAtSteady()
 
   assert(ud.begin() == ud.end());
 
-  std::vector<TwoDMatrix> dyn_ud; // Planner's objective derivatives, in Dynare form
+  std::vector<TwoDMatrix> dyn_ud;     // Planner's objective derivatives, in Dynare form
   dyn_ud.emplace_back(1, model.ny()); // Allocate Jacobian
   dyn_ud.back().zeros();
 
   for (int i = 2; i <= model.order(); i++)
     {
       // Higher order derivatives, as sparse (3-column) matrices
-      dyn_ud.emplace_back(static_cast<int>(NNZD[i-1]), 3);
+      dyn_ud.emplace_back(static_cast<int>(NNZD[i - 1]), 3);
       dyn_ud.back().zeros();
     }
 
@@ -56,13 +60,12 @@ KordwDynare::calcDerivativesAtSteady()
 
   for (int i = 1; i <= model.order(); i++)
     populateDerivativesContainer(dyn_ud, i);
-
 }
 
 void
-KordwDynare::populateDerivativesContainer(const std::vector<TwoDMatrix> &dyn_ud, int ord)
+KordwDynare::populateDerivativesContainer(const std::vector<TwoDMatrix>& dyn_ud, int ord)
 {
-  const TwoDMatrix &u = dyn_ud[ord-1];
+  const TwoDMatrix& u = dyn_ud[ord - 1];
 
   // utility derivatives FSSparseTensor instance
   auto udTi = std::make_unique<FSSparseTensor>(ord, model.ny(), 1);
@@ -83,8 +86,8 @@ KordwDynare::populateDerivativesContainer(const std::vector<TwoDMatrix> &dyn_ud,
   else // ord ≥ 2
     for (int i = 0; i < u.nrows(); i++)
       {
-        int j = static_cast<int>(u.get(i, 0))-1;
-        int i1 = static_cast<int>(u.get(i, 1))-1;
+        int j = static_cast<int>(u.get(i, 0)) - 1;
+        int i1 = static_cast<int>(u.get(i, 1)) - 1;
         if (j < 0 || i1 < 0)
           continue; // Discard empty entries (see comment in DynamicModelAC::unpackSparseMatrix())
 
@@ -107,220 +110,213 @@ KordwDynare::populateDerivativesContainer(const std::vector<TwoDMatrix> &dyn_ud,
 }
 
 template<>
-ctraits<Storage::unfold>::Tg &
+ctraits<Storage::unfold>::Tg&
 KOrderWelfare::g<Storage::unfold>()
 {
   return _ug;
 }
 template<>
-const ctraits<Storage::unfold>::Tg &
+const ctraits<Storage::unfold>::Tg&
 KOrderWelfare::g<Storage::unfold>() const
 {
   return _ug;
 }
 template<>
-ctraits<Storage::fold>::Tg &
+ctraits<Storage::fold>::Tg&
 KOrderWelfare::g<Storage::fold>()
 {
   return _fg;
 }
 template<>
-const ctraits<Storage::fold>::Tg &
+const ctraits<Storage::fold>::Tg&
 KOrderWelfare::g<Storage::fold>() const
 {
   return _fg;
 }
 template<>
-ctraits<Storage::unfold>::Tgs &
+ctraits<Storage::unfold>::Tgs&
 KOrderWelfare::gs<Storage::unfold>()
 {
   return _ugs;
 }
 template<>
-const ctraits<Storage::unfold>::Tgs &
+const ctraits<Storage::unfold>::Tgs&
 KOrderWelfare::gs<Storage::unfold>() const
 {
   return _ugs;
 }
 template<>
-ctraits<Storage::fold>::Tgs &
+ctraits<Storage::fold>::Tgs&
 KOrderWelfare::gs<Storage::fold>()
 {
   return _fgs;
 }
 template<>
-const ctraits<Storage::fold>::Tgs &
+const ctraits<Storage::fold>::Tgs&
 KOrderWelfare::gs<Storage::fold>() const
 {
   return _fgs;
 }
 
 template<>
-ctraits<Storage::unfold>::TU &
+ctraits<Storage::unfold>::TU&
 KOrderWelfare::U<Storage::unfold>()
 {
   return _uU;
 }
 template<>
-const ctraits<Storage::unfold>::TU &
+const ctraits<Storage::unfold>::TU&
 KOrderWelfare::U<Storage::unfold>() const
 {
   return _uU;
 }
 template<>
-ctraits<Storage::fold>::TU &
+ctraits<Storage::fold>::TU&
 KOrderWelfare::U<Storage::fold>()
 {
   return _fU;
 }
 template<>
-const ctraits<Storage::fold>::TU &
+const ctraits<Storage::fold>::TU&
 KOrderWelfare::U<Storage::fold>() const
 {
   return _fU;
 }
 template<>
-ctraits<Storage::unfold>::TW &
+ctraits<Storage::unfold>::TW&
 KOrderWelfare::W<Storage::unfold>()
 {
   return _uW;
 }
 template<>
-const ctraits<Storage::unfold>::TW &
+const ctraits<Storage::unfold>::TW&
 KOrderWelfare::W<Storage::unfold>() const
 {
   return _uW;
 }
 template<>
-ctraits<Storage::fold>::TW &
+ctraits<Storage::fold>::TW&
 KOrderWelfare::W<Storage::fold>()
 {
   return _fW;
 }
 template<>
-const ctraits<Storage::fold>::TW &
+const ctraits<Storage::fold>::TW&
 KOrderWelfare::W<Storage::fold>() const
 {
   return _fW;
 }
 template<>
-ctraits<Storage::unfold>::TWrond &
+ctraits<Storage::unfold>::TWrond&
 KOrderWelfare::Wrond<Storage::unfold>()
 {
   return _uWrond;
 }
 template<>
-const ctraits<Storage::unfold>::TWrond &
+const ctraits<Storage::unfold>::TWrond&
 KOrderWelfare::Wrond<Storage::unfold>() const
 {
   return _uWrond;
 }
 template<>
-ctraits<Storage::fold>::TWrond &
+ctraits<Storage::fold>::TWrond&
 KOrderWelfare::Wrond<Storage::fold>()
 {
   return _fWrond;
 }
 template<>
-const ctraits<Storage::fold>::TWrond &
+const ctraits<Storage::fold>::TWrond&
 KOrderWelfare::Wrond<Storage::fold>() const
 {
   return _fWrond;
 }
 template<>
-ctraits<Storage::unfold>::TGstack &
+ctraits<Storage::unfold>::TGstack&
 KOrderWelfare::Gstack<Storage::unfold>()
 {
   return _uGstack;
 }
 template<>
-const ctraits<Storage::unfold>::TGstack &
+const ctraits<Storage::unfold>::TGstack&
 KOrderWelfare::Gstack<Storage::unfold>() const
 {
   return _uGstack;
 }
 template<>
-ctraits<Storage::fold>::TGstack &
+ctraits<Storage::fold>::TGstack&
 KOrderWelfare::Gstack<Storage::fold>()
 {
   return _fGstack;
 }
 template<>
-const ctraits<Storage::fold>::TGstack &
+const ctraits<Storage::fold>::TGstack&
 KOrderWelfare::Gstack<Storage::fold>() const
 {
   return _fGstack;
 }
 template<>
-ctraits<Storage::unfold>::TXstack &
+ctraits<Storage::unfold>::TXstack&
 KOrderWelfare::Xstack<Storage::unfold>()
 {
   return _uXstack;
 }
 template<>
-const ctraits<Storage::unfold>::TXstack &
+const ctraits<Storage::unfold>::TXstack&
 KOrderWelfare::Xstack<Storage::unfold>() const
 {
   return _uXstack;
 }
 template<>
-ctraits<Storage::fold>::TXstack &
+ctraits<Storage::fold>::TXstack&
 KOrderWelfare::Xstack<Storage::fold>()
 {
   return _fXstack;
 }
 template<>
-const ctraits<Storage::fold>::TXstack &
+const ctraits<Storage::fold>::TXstack&
 KOrderWelfare::Xstack<Storage::fold>() const
 {
   return _fXstack;
 }
 template<>
-ctraits<Storage::unfold>::Tm &
+ctraits<Storage::unfold>::Tm&
 KOrderWelfare::m<Storage::unfold>()
 {
   return _um;
 }
 template<>
-const ctraits<Storage::unfold>::Tm &
+const ctraits<Storage::unfold>::Tm&
 KOrderWelfare::m<Storage::unfold>() const
 {
   return _um;
 }
 template<>
-ctraits<Storage::fold>::Tm &
+ctraits<Storage::fold>::Tm&
 KOrderWelfare::m<Storage::fold>()
 {
   return _fm;
 }
 template<>
-const ctraits<Storage::fold>::Tm &
+const ctraits<Storage::fold>::Tm&
 KOrderWelfare::m<Storage::fold>() const
 {
   return _fm;
 }
 
-KOrderWelfare::KOrderWelfare(int num_stat, int num_pred,
-                             int num_both, int num_forw, int nu, int ord,
-                             double discount_factor,
-                             const TensorContainer<FSSparseTensor> &ucont,
-                             const FGSContainer &g_arg,
-                             const FGSContainer &gs_arg,
-                             const TwoDMatrix &v,
-                             Journal &jr) :
-  ypart(num_stat, num_pred, num_both, num_forw),
-  ny(ypart.ny()), nu(nu), maxk(ucont.getMaxDim()), order(ord),
-  discount_factor{discount_factor}, nvs{ypart.nys(), nu, nu, 1},
-  _uU(4), _fU(4), _uW(4), _fW(4), _uWrond(4), _fWrond(4), _ug(4),
-  _fg(g_arg), _ugs(4), _fgs(gs_arg), _uXstack(&_ug, ny),
-  _fXstack(&_fg, ny), _uGstack(&_ugs, ypart.nys(), nu),
-  _fGstack(&_fgs, ypart.nys(), nu), _um(maxk, v),
-  _fm(_um), u(ucont), journal(jr)
-{
-  KORD_RAISE_IF(v.ncols() != nu,
-                "Wrong number of columns of Vcov in KOrderWelfare constructor");
-  KORD_RAISE_IF(nu != v.nrows(),
-                "Wrong number of rows of Vcov in KOrderWelfare constructor");
+KOrderWelfare::KOrderWelfare(int num_stat, int num_pred, int num_both, int num_forw, int nu,
+                             int ord, double discount_factor,
+                             const TensorContainer<FSSparseTensor>& ucont,
+                             const FGSContainer& g_arg, const FGSContainer& gs_arg,
+                             const TwoDMatrix& v, Journal& jr) :
+    ypart(num_stat, num_pred, num_both, num_forw),
+    ny(ypart.ny()), nu(nu), maxk(ucont.getMaxDim()),
+    order(ord), discount_factor {discount_factor}, nvs {ypart.nys(), nu, nu, 1}, _uU(4), _fU(4),
+    _uW(4), _fW(4), _uWrond(4), _fWrond(4), _ug(4), _fg(g_arg), _ugs(4), _fgs(gs_arg),
+    _uXstack(&_ug, ny), _fXstack(&_fg, ny), _uGstack(&_ugs, ypart.nys(), nu),
+    _fGstack(&_fgs, ypart.nys(), nu), _um(maxk, v), _fm(_um), u(ucont), journal(jr)
+{
+  KORD_RAISE_IF(v.ncols() != nu, "Wrong number of columns of Vcov in KOrderWelfare constructor");
+  KORD_RAISE_IF(nu != v.nrows(), "Wrong number of rows of Vcov in KOrderWelfare constructor");
   for (int ord = 1; ord <= order; ord++)
     {
       JournalRecordPair pa(journal);
@@ -328,7 +324,7 @@ KOrderWelfare::KOrderWelfare(int num_stat, int num_pred,
       for (int j = 0; j <= ord; j++)
         for (int i = 0; i <= j; i++)
           {
-            Symmetry sym{ord-j, i, 0, j-i};
+            Symmetry sym {ord - j, i, 0, j - i};
             pa << "Recovering symmetry " << sym << "\n" << endrec;
             auto U_sym = faaDiBrunoU<Storage::fold>(sym);
             U<Storage::fold>().insert(std::move(U_sym));
@@ -354,21 +350,18 @@ KOrderWelfare::KOrderWelfare(int num_stat, int num_pred,
 
 template<>
 void
-KOrderWelfare::sylvesterSolve<Storage::unfold>(ctraits<Storage::unfold>::Ttensor &der) const
+KOrderWelfare::sylvesterSolve<Storage::unfold>(ctraits<Storage::unfold>::Ttensor& der) const
 {
   JournalRecordPair pa(journal);
   pa << "Sylvester equation for dimension = " << der.getSym()[0] << endrec;
-  KORD_RAISE_IF(!der.isFinite(),
-                "RHS of Sylverster is not finite");
-  TwoDMatrix gs_y(gs<Storage::unfold>().get(Symmetry{1, 0, 0, 0}));
-  TwoDMatrix A(1,1);
+  KORD_RAISE_IF(!der.isFinite(), "RHS of Sylverster is not finite");
+  TwoDMatrix gs_y(gs<Storage::unfold>().get(Symmetry {1, 0, 0, 0}));
+  TwoDMatrix A(1, 1);
   A.unit();
-  TwoDMatrix B(1,1);
+  TwoDMatrix B(1, 1);
   B.unit();
   B.mult(-discount_factor);
-  GeneralSylvester sylv(der.getSym()[0], 1, ypart.nys(),
-                        0,
-                        A.getData(), B.getData(),
+  GeneralSylvester sylv(der.getSym()[0], 1, ypart.nys(), 0, A.getData(), B.getData(),
                         gs_y.getData(), der.getData());
   sylv.solve();
 }
@@ -380,10 +373,10 @@ KOrderWelfare::sylvesterSolve<Storage::unfold>(ctraits<Storage::unfold>::Ttensor
 
 template<>
 void
-KOrderWelfare::sylvesterSolve<Storage::fold>(ctraits<Storage::fold>::Ttensor &der) const
+KOrderWelfare::sylvesterSolve<Storage::fold>(ctraits<Storage::fold>::Ttensor& der) const
 {
   ctraits<Storage::unfold>::Ttensor tmp(der);
   sylvesterSolve<Storage::unfold>(tmp);
   ctraits<Storage::fold>::Ttensor ftmp(tmp);
-  der.getData() = const_cast<const Vector &>(ftmp.getData());
+  der.getData() = const_cast<const Vector&>(ftmp.getData());
 }
diff --git a/mex/sources/k_order_welfare/k_ord_objective.hh b/mex/sources/k_order_welfare/k_ord_objective.hh
index 35070edd46670a164df34ba5a5bba0a3c7fe8001..45dfda5c9278b27731af0db82854b70cfe13f846 100644
--- a/mex/sources/k_order_welfare/k_ord_objective.hh
+++ b/mex/sources/k_order_welfare/k_ord_objective.hh
@@ -28,40 +28,43 @@ class KordwDynare;
 class KordwDynare
 {
 public:
-  KordpDynare &model;
-  const ConstVector &NNZD;
+  KordpDynare& model;
+  const ConstVector& NNZD;
+
 private:
-  Journal &journal;
-  Vector &params;
+  Journal& journal;
+  Vector& params;
   Vector resid;
   TensorContainer<FSSparseTensor> ud; // planner's objective derivatives, in Dynare++ form
-  std::vector<int> dynppToDyn; // Maps Dynare++ jacobian variable indices to Dynare ones
-  std::vector<int> dynToDynpp; // Maps Dynare jacobian variable indices to Dynare++ ones
+  std::vector<int> dynppToDyn;        // Maps Dynare++ jacobian variable indices to Dynare ones
+  std::vector<int> dynToDynpp;        // Maps Dynare jacobian variable indices to Dynare++ ones
   std::unique_ptr<ObjectiveAC> objectiveFile;
+
 public:
-  KordwDynare(KordpDynare &m, ConstVector &NNZD_arg, Journal &jr, Vector &inParams, std::unique_ptr<ObjectiveAC> objectiveFile_arg, const std::vector<int> &varOrder);
+  KordwDynare(KordpDynare& m, ConstVector& NNZD_arg, Journal& jr, Vector& inParams,
+              std::unique_ptr<ObjectiveAC> objectiveFile_arg, const std::vector<int>& varOrder);
   void calcDerivativesAtSteady();
-  void populateDerivativesContainer(const std::vector<TwoDMatrix> &dyn_ud, int ord);
-  const TensorContainer<FSSparseTensor> &
+  void populateDerivativesContainer(const std::vector<TwoDMatrix>& dyn_ud, int ord);
+  const TensorContainer<FSSparseTensor>&
   getPlannerObjDerivatives() const
   {
     return ud;
   }
-  const KordpDynare &
+  const KordpDynare&
   getModel() const
   {
     return model;
   }
-  const Vector &
+  const Vector&
   getResid() const
   {
     return resid;
   }
+
 private:
   /* Computes the permutations mapping back and forth between Dynare and
      Dynare++ orderings of variables */
-  void computeJacobianPermutation(const std::vector<int> &var_order);
-
+  void computeJacobianPermutation(const std::vector<int>& var_order);
 };
 
 class KOrderWelfare
@@ -98,54 +101,50 @@ public:
 
   /* Planner objective derivatives: just a reference to the container of sparse
      tensors of the derivatives, lives outside the class */
-  const TensorContainer<FSSparseTensor> &u;
+  const TensorContainer<FSSparseTensor>& u;
 
   /* These are the declarations of the template functions accessing the
      containers. We declare template methods for accessing containers depending
      on ‘fold’ and ‘unfold’ flag, we implement their specializations*/
   template<Storage t>
-  typename ctraits<t>::Tg &g();
+  typename ctraits<t>::Tg& g();
   template<Storage t>
-  const typename ctraits<t>::Tg &g() const;
+  const typename ctraits<t>::Tg& g() const;
   template<Storage t>
-  typename ctraits<t>::Tgs &gs();
+  typename ctraits<t>::Tgs& gs();
   template<Storage t>
-  const typename ctraits<t>::Tgs &gs() const;
+  const typename ctraits<t>::Tgs& gs() const;
   template<Storage t>
-  typename ctraits<t>::TU &U();
+  typename ctraits<t>::TU& U();
   template<Storage t>
-  const typename ctraits<t>::TU &U() const;
+  const typename ctraits<t>::TU& U() const;
   template<Storage t>
-  typename ctraits<t>::TW &W();
+  typename ctraits<t>::TW& W();
   template<Storage t>
-  const typename ctraits<t>::TW &W() const;
+  const typename ctraits<t>::TW& W() const;
   template<Storage t>
-  typename ctraits<t>::TWrond &Wrond();
+  typename ctraits<t>::TWrond& Wrond();
   template<Storage t>
-  const typename ctraits<t>::TWrond &Wrond() const;
+  const typename ctraits<t>::TWrond& Wrond() const;
   template<Storage t>
-  typename ctraits<t>::TXstack &Xstack();
+  typename ctraits<t>::TXstack& Xstack();
   template<Storage t>
-  const typename ctraits<t>::TXstack &Xstack() const;
+  const typename ctraits<t>::TXstack& Xstack() const;
   template<Storage t>
-  typename ctraits<t>::TGstack &Gstack();
+  typename ctraits<t>::TGstack& Gstack();
   template<Storage t>
-  const typename ctraits<t>::TGstack &Gstack() const;
+  const typename ctraits<t>::TGstack& Gstack() const;
   template<Storage t>
-  typename ctraits<t>::Tm &m();
+  typename ctraits<t>::Tm& m();
   template<Storage t>
-  const typename ctraits<t>::Tm &m() const;
+  const typename ctraits<t>::Tm& m() const;
 
-  Journal &journal;
+  Journal& journal;
 
 public:
-  KOrderWelfare(int num_stat, int num_pred, int num_both,
-                int num_forw, int nu, int ord, double discount_factor,
-                const TensorContainer<FSSparseTensor> &ucont,
-                const FGSContainer &g,
-                const FGSContainer &gs,
-                const TwoDMatrix &v,
-                Journal &jr);
+  KOrderWelfare(int num_stat, int num_pred, int num_both, int num_forw, int nu, int ord,
+                double discount_factor, const TensorContainer<FSSparseTensor>& ucont,
+                const FGSContainer& g, const FGSContainer& gs, const TwoDMatrix& v, Journal& jr);
 
   /* Performs k-order step provided that k=2 or the k−1-th step has been
      run, this is the core method */
@@ -156,22 +155,22 @@ public:
   template<Storage t>
   double check(int dim) const;
 
-  const FGSContainer &
+  const FGSContainer&
   getFoldU() const
   {
     return _fU;
   }
-  const UGSContainer &
+  const UGSContainer&
   getUnfoldU() const
   {
     return _uU;
   }
-  const FGSContainer &
+  const FGSContainer&
   getFoldW() const
   {
     return _fW;
   }
-  const UGSContainer &
+  const UGSContainer&
   getUnfoldW() const
   {
     return _uW;
@@ -186,14 +185,15 @@ protected:
   /* Calculates derivatives of U by Faà Di Bruno for the sparse container of
      planner's objective derivatives and the container for the decision rule derivatives*/
   template<Storage t>
-  std::unique_ptr<typename ctraits<t>::Ttensor> faaDiBrunoU(const Symmetry &sym) const;
-  /* Calculates derivatives of the compounded functions W and Gstack using the Faà Di Bruno formula*/
+  std::unique_ptr<typename ctraits<t>::Ttensor> faaDiBrunoU(const Symmetry& sym) const;
+  /* Calculates derivatives of the compounded functions W and Gstack using the Faà Di Bruno
+   * formula*/
   template<Storage t>
-  std::unique_ptr<typename ctraits<t>::Ttensor> faaDiBrunoW(const Symmetry &sym) const;
+  std::unique_ptr<typename ctraits<t>::Ttensor> faaDiBrunoW(const Symmetry& sym) const;
 
   /* Solves the sylvester equation (templated fold, and unfold) */
   template<Storage t>
-  void sylvesterSolve(typename ctraits<t>::Ttensor &der) const;
+  void sylvesterSolve(typename ctraits<t>::Ttensor& der) const;
 
   // Recovers W_y*ⁱ
   template<Storage t>
@@ -230,7 +230,6 @@ protected:
   typename ctraits<t>::Ttensor calcJ_ik(int i, int k) const;
   template<Storage t>
   typename ctraits<t>::Ttensor calcJ_k(int k) const;
-
 };
 
 /* Here we implement Faà Di Bruno formula
@@ -242,7 +241,7 @@ protected:
    where s is a given outer symmetry and k is the dimension of the symmetry. */
 template<Storage t>
 std::unique_ptr<typename ctraits<t>::Ttensor>
-KOrderWelfare::faaDiBrunoU(const Symmetry &sym) const
+KOrderWelfare::faaDiBrunoU(const Symmetry& sym) const
 {
   JournalRecordPair pa(journal);
   pa << "Faà Di Bruno U container for " << sym << endrec;
@@ -255,7 +254,7 @@ KOrderWelfare::faaDiBrunoU(const Symmetry &sym) const
 /* The same as KOrder::faaDiBrunoW(), but for W and G stack. */
 template<Storage t>
 std::unique_ptr<typename ctraits<t>::Ttensor>
-KOrderWelfare::faaDiBrunoW(const Symmetry &sym) const
+KOrderWelfare::faaDiBrunoW(const Symmetry& sym) const
 {
   JournalRecordPair pa(journal);
   pa << "Faà Di Bruno G container for " << sym << endrec;
@@ -270,32 +269,33 @@ template<Storage t>
 void
 KOrderWelfare::performStep(int order)
 {
-  KORD_RAISE_IF(order-1 != W<t>().getMaxDim() and order > 1, "Wrong order for KOrder::performStep");
+  KORD_RAISE_IF(order - 1 != W<t>().getMaxDim() and order > 1,
+                "Wrong order for KOrder::performStep");
   JournalRecordPair pa(journal);
   pa << "Performing step for order = " << order << endrec;
 
   recover_y<t>(order);
 
   for (int i = 0; i < order; i++)
-    recover_yu<t>(i, order-i);
+    recover_yu<t>(i, order - i);
 
-  recover_ys<t>(order-1, 1);
+  recover_ys<t>(order - 1, 1);
 
   for (int j = 2; j < order; j++)
     {
-      for (int i = 1; i <= j-1; i++)
-        recover_yus<t>(order-j, i, j-i);
-      recover_ys<t>(order-j, j);
-      recover_yus<t>(0, order-j, j);
+      for (int i = 1; i <= j - 1; i++)
+        recover_yus<t>(order - j, i, j - i);
+      recover_ys<t>(order - j, j);
+      recover_yus<t>(0, order - j, j);
     }
 
   recover_s<t>(order);
 }
 
-/* Here we solve [F_yⁱ]=0. First we calculate conditional W_yⁱ (it misses l=i since W_yⁱ does not exist yet). Then calculate conditional F_yⁱ and
-   we have the right hand side of equation. Since we miss two orders, we solve
-   by Sylvester, and  the solution as the derivative g_yⁱ. Then we need
-   to update G_yⁱ running multAndAdd() for both dimensions 1 and i.
+/* Here we solve [F_yⁱ]=0. First we calculate conditional W_yⁱ (it misses l=i since W_yⁱ does not
+   exist yet). Then calculate conditional F_yⁱ and we have the right hand side of equation. Since we
+   miss two orders, we solve by Sylvester, and  the solution as the derivative g_yⁱ. Then we need to
+   update G_yⁱ running multAndAdd() for both dimensions 1 and i.
 
    Requires: everything at order ≤ i−1
 
@@ -305,7 +305,7 @@ template<Storage t>
 void
 KOrderWelfare::recover_y(int i)
 {
-  Symmetry sym{i, 0, 0, 0};
+  Symmetry sym {i, 0, 0, 0};
   JournalRecordPair pa(journal);
   pa << "Conditional welfare: recovering symmetry " << sym << "\n" << endrec;
 
@@ -335,7 +335,7 @@ template<Storage t>
 void
 KOrderWelfare::recover_yu(int i, int j)
 {
-  Symmetry sym{i, j, 0, 0};
+  Symmetry sym {i, j, 0, 0};
   JournalRecordPair pa(journal);
   pa << "Conditional welfare: recovering symmetry " << sym << endrec;
 
@@ -347,7 +347,6 @@ KOrderWelfare::recover_yu(int i, int j)
   W_yiuj.add(discount_factor, *Wrond_yiuj_ptr);
 
   W<t>().insert(std::make_unique<typename ctraits<t>::Ttensor>(W_yiuj));
-
 }
 
 /* Here we solve [F_yⁱσʲ]+[Dᵢⱼ]+[Eᵢⱼ]=0 to obtain W_yⁱσʲ. We calculate
@@ -367,7 +366,7 @@ template<Storage t>
 void
 KOrderWelfare::recover_ys(int i, int j)
 {
-  Symmetry sym{i, 0, 0, j};
+  Symmetry sym {i, 0, 0, j};
   JournalRecordPair pa(journal);
   pa << "Conditional welfare: recovering symmetry " << sym << endrec;
 
@@ -396,7 +395,7 @@ KOrderWelfare::recover_ys(int i, int j)
 
       W<t>().insert(std::make_unique<typename ctraits<t>::Ttensor>(W_yisj));
 
-      Gstack<t>().multAndAdd(i+j, W<t>(), *Wrond_yisj_ptr);
+      Gstack<t>().multAndAdd(i + j, W<t>(), *Wrond_yisj_ptr);
     }
 }
 
@@ -417,7 +416,7 @@ template<Storage t>
 void
 KOrderWelfare::recover_yus(int i, int j, int k)
 {
-  Symmetry sym{i, j, 0, k};
+  Symmetry sym {i, j, 0, k};
   JournalRecordPair pa(journal);
   pa << "Conditional welfare: recovering symmetry " << sym << endrec;
 
@@ -443,7 +442,7 @@ KOrderWelfare::recover_yus(int i, int j, int k)
 
       W<t>().insert(std::make_unique<typename ctraits<t>::Ttensor>(W_yiujsk));
 
-      Gstack<t>().multAndAdd(i+j+k, W<t>(), *Wrond_yiujsk_ptr);
+      Gstack<t>().multAndAdd(i + j + k, W<t>(), *Wrond_yiujsk_ptr);
     }
 }
 
@@ -463,7 +462,7 @@ template<Storage t>
 void
 KOrderWelfare::recover_s(int i)
 {
-  Symmetry sym{0, 0, 0, i};
+  Symmetry sym {0, 0, 0, i};
   JournalRecordPair pa(journal);
   pa << "Conditional welfare: recovering symmetry " << sym << endrec;
 
@@ -489,7 +488,7 @@ KOrderWelfare::recover_s(int i)
           W_si.add(-1.0, J_i);
         }
 
-      W_si.mult(1/(1-discount_factor));
+      W_si.mult(1 / (1 - discount_factor));
 
       W<t>().insert(std::make_unique<typename ctraits<t>::Ttensor>(W_si));
 
@@ -497,15 +496,16 @@ KOrderWelfare::recover_s(int i)
     }
 }
 
-/* Here we calculate and insert Wrond_yⁱuʲu′ᵐσᵏ⁻ᵐ for m=1,…,k. The derivatives are inserted only for k−m being even. */
+/* Here we calculate and insert Wrond_yⁱuʲu′ᵐσᵏ⁻ᵐ for m=1,…,k. The derivatives are inserted only for
+ * k−m being even. */
 template<Storage t>
 void
 KOrderWelfare::fillWrond(int i, int j, int k)
 {
   for (int m = 1; m <= k; m++)
-    if (is_even(k-m))
+    if (is_even(k - m))
       {
-        auto Wrond_yiujupms = faaDiBrunoW<t>(Symmetry{i, j, m, k-m});
+        auto Wrond_yiujupms = faaDiBrunoW<t>(Symmetry {i, j, m, k - m});
         Wrond<t>().insert(std::move(Wrond_yiujupms));
       }
 }
@@ -519,12 +519,12 @@ template<Storage t>
 typename ctraits<t>::Ttensor
 KOrderWelfare::calcH_ijk(int i, int j, int k) const
 {
-  typename ctraits<t>::Ttensor res(1, TensorDimens(Symmetry{i, j, 0, 0}, nvs));
+  typename ctraits<t>::Ttensor res(1, TensorDimens(Symmetry {i, j, 0, 0}, nvs));
   res.zeros();
   if (is_even(k))
     {
-      auto tmp = faaDiBrunoW<t>(Symmetry{i, j, k, 0});
-      tmp->contractAndAdd(2, res, m<t>().get(Symmetry{k}));
+      auto tmp = faaDiBrunoW<t>(Symmetry {i, j, k, 0});
+      tmp->contractAndAdd(2, res, m<t>().get(Symmetry {k}));
     }
   res.mult(-discount_factor);
   return res;
@@ -542,13 +542,13 @@ template<Storage t>
 typename ctraits<t>::Ttensor
 KOrderWelfare::calcJ_ijk(int i, int j, int k) const
 {
-  typename ctraits<t>::Ttensor res(1, TensorDimens(Symmetry{i, j, 0, 0}, nvs));
+  typename ctraits<t>::Ttensor res(1, TensorDimens(Symmetry {i, j, 0, 0}, nvs));
   res.zeros();
-  for (int n = 2; n <= k-1; n += 2)
+  for (int n = 2; n <= k - 1; n += 2)
     {
-      auto tmp = faaDiBrunoW<t>(Symmetry{i, j, n, k-n});
+      auto tmp = faaDiBrunoW<t>(Symmetry {i, j, n, k - n});
       tmp->mult(static_cast<double>(PascalTriangle::noverk(k, n)));
-      tmp->contractAndAdd(2, res, m<t>().get(Symmetry{n}));
+      tmp->contractAndAdd(2, res, m<t>().get(Symmetry {n}));
     }
   res.mult(-discount_factor);
   return res;
@@ -590,8 +590,7 @@ template<Storage t>
 double
 KOrderWelfare::check(int dim) const
 {
-  KORD_RAISE_IF(dim > W<t>().getMaxDim(),
-                "Wrong dimension for KOrderWelfare::check");
+  KORD_RAISE_IF(dim > W<t>().getMaxDim(), "Wrong dimension for KOrderWelfare::check");
   JournalRecordPair pa(journal);
   pa << "Checking residuals for order = " << dim << endrec;
 
@@ -600,7 +599,7 @@ KOrderWelfare::check(int dim) const
   // Check for F_yⁱuʲ=0
   for (int i = 0; i <= dim; i++)
     {
-      Symmetry sym{dim-i, i, 0, 0};
+      Symmetry sym {dim - i, i, 0, 0};
       auto r = W<t>().get(sym);
       r.add(-1.0, U<t>().get(sym));
       r.add(-discount_factor, Wrond<t>().get(sym));
@@ -610,14 +609,14 @@ KOrderWelfare::check(int dim) const
     }
 
   // Check for F_yⁱuʲu′ᵏ+Hᵢⱼₖ+Jᵢⱼₖ=0
-  for (auto &si : SymmetrySet(dim, 3))
+  for (auto& si : SymmetrySet(dim, 3))
     {
       int i = si[0];
       int j = si[1];
       int k = si[2];
-      if (i+j > 0 && k > 0 && is_even(k))
+      if (i + j > 0 && k > 0 && is_even(k))
         {
-          Symmetry sym{i, j, 0, k};
+          Symmetry sym {i, j, 0, k};
           auto r = W<t>().get(sym);
           r.add(-1.0, U<t>().get(sym));
           r.add(-discount_factor, Wrond<t>().get(sym));
@@ -634,7 +633,7 @@ KOrderWelfare::check(int dim) const
   // Check for F_σⁱ+Dᵢ+Eᵢ=0
   if (is_even(dim))
     {
-      Symmetry sym{0, 0, 0, dim};
+      Symmetry sym {0, 0, 0, dim};
       auto r = W<t>().get(sym);
       r.add(-1.0, U<t>().get(sym));
       r.add(-discount_factor, Wrond<t>().get(sym));
diff --git a/mex/sources/k_order_welfare/k_order_welfare.cc b/mex/sources/k_order_welfare/k_order_welfare.cc
index 259f21705438d98ec3ff2fbd8b89b58de77cb42a..3178d91f7c733430c8bfe39ef65594f76b58b41e 100644
--- a/mex/sources/k_order_welfare/k_order_welfare.cc
+++ b/mex/sources/k_order_welfare/k_order_welfare.cc
@@ -17,17 +17,17 @@
  * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#include "dynamic_m.hh"
 #include "dynamic_dll.hh"
+#include "dynamic_m.hh"
 #include "objective_m.hh"
 
+#include "SylvException.hh"
 #include "approximation.hh"
 #include "approximation_welfare.hh"
-#include "exception.hh"
 #include "dynare_exception.hh"
+#include "exception.hh"
 #include "kord_exception.hh"
 #include "tl_exception.hh"
-#include "SylvException.hh"
 
 #include <algorithm>
 #include <cassert>
@@ -37,13 +37,13 @@
 /* Convert MATLAB Dynare endo and exo names cell array to a vector<string> array of
    string pointers. */
 std::vector<std::string>
-DynareMxArrayToString(const mxArray *mxFldp)
+DynareMxArrayToString(const mxArray* mxFldp)
 {
   assert(mxIsCell(mxFldp));
   std::vector<std::string> r;
   for (size_t i = 0; i < mxGetNumberOfElements(mxFldp); i++)
     {
-      const mxArray *cell_mx = mxGetCell(mxFldp, i);
+      const mxArray* cell_mx = mxGetCell(mxFldp, i);
       if (!(cell_mx && mxIsChar(cell_mx)))
         mexErrMsgTxt("Cell is not a character array");
       r.emplace_back(mxArrayToString(cell_mx));
@@ -62,48 +62,60 @@ DynareMxArrayToString(const mxArray *mxFldp)
 std::vector<std::string> W_fieldnames;
 
 void
-copy_derivatives(mxArray *destin, const Symmetry &sym, const FGSContainer &derivs, const char *fieldname)
+copy_derivatives(mxArray* destin, const Symmetry& sym, const FGSContainer& derivs,
+                 const char* fieldname)
 {
-  const FGSTensor &x = derivs.get(sym);
+  const FGSTensor& x = derivs.get(sym);
   auto x_unfolded = x.unfold();
   int n = x_unfolded->nrows();
   int m = x_unfolded->ncols();
-  mxArray *tmp = mxCreateDoubleMatrix(n, m, mxREAL);
-  std::copy_n(x_unfolded->getData().base(), n*m, mxGetPr(tmp));
+  mxArray* tmp = mxCreateDoubleMatrix(n, m, mxREAL);
+  std::copy_n(x_unfolded->getData().base(), n * m, mxGetPr(tmp));
   mxSetField(destin, 0, fieldname, tmp);
 }
 
-/* The k_order_welfare function computes the conditional welfare starting from the non-stochastic steady state and the derivatives of the felicity and welfare functions U(h(yₜ₋₁, uₜ, σ)) and W(yₜ₋₁, uₜ, σ). The unconditional welfare shall be introduced in a future version with the update of the dynare_simul_.
+/*
+The k_order_welfare function computes the conditional welfare starting from the non-stochastic
+steady state and the derivatives of the felicity and welfare functions U(h(yₜ₋₁, uₜ, σ)) and W(yₜ₋₁,
+uₜ, σ). The unconditional welfare shall be introduced in a future version with the update of the
+dynare_simul_.
 
 The routine proceeds in several steps:
-1. Computation of the kth-order policy functions: the code is a copy-paste from the k_order_perturbation.cc file
-2. Computation of the kth-order derivatives of the felicity and of the welfare functions. The call to the approxAtSteady method in the ApproximationWelfare class carries out the necessary operation 
-   - Importing the derivatives of the felicity function with the calcDerivativesAtSteady() method of the KordwDynare class. It relies on the Matlab-generated files, which are handled by the ObjectiveAC and ObjectiveMFile classes
-   - Pinpointing the derivatives of the felicity and welfare functions. The performStep method of the KOrderWelfare class carries out the calculations,resorting to the FaaDiBruno class and its methods to get the needed intermediary results.
+1. Computation of the kth-order policy functions: the code is a copy-paste from the
+   k_order_perturbation.cc file
+2. Computation of the kth-order derivatives of the felicity and of the welfare functions. The call
+   to the approxAtSteady method in the ApproximationWelfare class carries out the necessary
+   operation
+   - Importing the derivatives of the felicity function with the calcDerivativesAtSteady() method of
+     the KordwDynare class. It relies on the Matlab-generated files, which are handled by the
+     ObjectiveAC and ObjectiveMFile classes
+   - Pinpointing the derivatives of the felicity and welfare functions. The performStep method of
+     the KOrderWelfare class carries out the calculations,resorting to the FaaDiBruno class and its
+     methods to get the needed intermediary results.
 */
 
-extern "C" {
+extern "C"
+{
 
-  void mexFunction(int nlhs, mxArray *plhs[],
-                   int nrhs, const mxArray *prhs[])
+  void
+  mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
   {
     if (nlhs != 1 || nrhs != 3)
       mexErrMsgTxt("Must have exactly 3 input arguments and 1 output argument");
 
-    const mxArray *dr_mx = prhs[0];
-    const mxArray *M_mx = prhs[1];
-    const mxArray *options_mx = prhs[2];
+    const mxArray* dr_mx = prhs[0];
+    const mxArray* M_mx = prhs[1];
+    const mxArray* options_mx = prhs[2];
 
-    auto get_int_field = [](const mxArray *struct_mx, const std::string &fieldname)
-                         {
-                           mxArray *field_mx = mxGetField(struct_mx, 0, fieldname.c_str());
-                           if (!(field_mx && mxIsScalar(field_mx) && mxIsNumeric(field_mx)))
-                             mexErrMsgTxt(("Field `" + fieldname + "' should be a numeric scalar").c_str());
-                           return static_cast<int>(mxGetScalar(field_mx));
-                         };
+    auto get_int_field = [](const mxArray* struct_mx, const std::string& fieldname) {
+      mxArray* field_mx = mxGetField(struct_mx, 0, fieldname.c_str());
+      if (!(field_mx && mxIsScalar(field_mx) && mxIsNumeric(field_mx)))
+        mexErrMsgTxt(("Field `" + fieldname + "' should be a numeric scalar").c_str());
+      return static_cast<int>(mxGetScalar(field_mx));
+    };
 
     // Extract various fields from options_
-    const mxArray *ramsey_policy_mx = mxGetField(options_mx, 0, "ramsey_policy");
+    const mxArray* ramsey_policy_mx = mxGetField(options_mx, 0, "ramsey_policy");
     if (!(ramsey_policy_mx && mxIsLogicalScalar(ramsey_policy_mx)))
       mexErrMsgTxt("options_.ramsey_policy should be a logical scalar");
     bool ramsey_policy = static_cast<bool>(mxGetScalar(ramsey_policy_mx));
@@ -111,53 +123,52 @@ extern "C" {
     if (ramsey_policy == false)
       mexErrMsgTxt("The considered model must be a Ramsey-typed model !");
 
-
     const int kOrder = get_int_field(options_mx, "order");
     if (kOrder < 1)
       mexErrMsgTxt("options_.order must be at least 1");
 
-    const mxArray *use_dll_mx = mxGetField(options_mx, 0, "use_dll");
+    const mxArray* use_dll_mx = mxGetField(options_mx, 0, "use_dll");
     if (!(use_dll_mx && mxIsLogicalScalar(use_dll_mx)))
       mexErrMsgTxt("options_.use_dll should be a logical scalar");
     bool use_dll = static_cast<bool>(mxGetScalar(use_dll_mx));
 
-    double qz_criterium = 1+1e-6;
-    const mxArray *qz_criterium_mx = mxGetField(options_mx, 0, "qz_criterium");
+    double qz_criterium = 1 + 1e-6;
+    const mxArray* qz_criterium_mx = mxGetField(options_mx, 0, "qz_criterium");
     if (qz_criterium_mx && mxIsScalar(qz_criterium_mx) && mxIsNumeric(qz_criterium_mx))
       qz_criterium = mxGetScalar(qz_criterium_mx);
 
-    const mxArray *threads_mx = mxGetField(options_mx, 0, "threads");
+    const mxArray* threads_mx = mxGetField(options_mx, 0, "threads");
     if (!threads_mx)
       mexErrMsgTxt("Can't find field options_.threads");
-    const mxArray *num_threads_mx = mxGetField(threads_mx, 0, "k_order_perturbation");
+    const mxArray* num_threads_mx = mxGetField(threads_mx, 0, "k_order_perturbation");
     if (!(num_threads_mx && mxIsScalar(num_threads_mx) && mxIsNumeric(num_threads_mx)))
       mexErrMsgTxt("options_.threads.k_order_perturbation be a numeric scalar");
     int num_threads = static_cast<int>(mxGetScalar(num_threads_mx));
 
-    const mxArray *debug_mx = mxGetField(options_mx, 0, "debug");
+    const mxArray* debug_mx = mxGetField(options_mx, 0, "debug");
     if (!(debug_mx && mxIsLogicalScalar(debug_mx)))
       mexErrMsgTxt("options_.debug should be a logical scalar");
     bool debug = static_cast<bool>(mxGetScalar(debug_mx));
 
-    const mxArray *pruning_mx = mxGetField(options_mx, 0, "pruning");
+    const mxArray* pruning_mx = mxGetField(options_mx, 0, "pruning");
     if (!(pruning_mx && mxIsLogicalScalar(pruning_mx)))
       mexErrMsgTxt("options_.pruning should be a logical scalar");
     bool pruning = static_cast<bool>(mxGetScalar(pruning_mx));
 
     // Extract various fields from M_
-    const mxArray *fname_mx = mxGetField(M_mx, 0, "fname");
+    const mxArray* fname_mx = mxGetField(M_mx, 0, "fname");
     if (!(fname_mx && mxIsChar(fname_mx) && mxGetM(fname_mx) == 1))
       mexErrMsgTxt("M_.fname should be a character string");
-    std::string fname{mxArrayToString(fname_mx)};
+    std::string fname {mxArrayToString(fname_mx)};
 
-    const mxArray *params_mx = mxGetField(M_mx, 0, "params");
+    const mxArray* params_mx = mxGetField(M_mx, 0, "params");
     if (!(params_mx && mxIsDouble(params_mx)))
       mexErrMsgTxt("M_.params should be a double precision array");
-    Vector modParams{ConstVector{params_mx}};
+    Vector modParams {ConstVector {params_mx}};
     if (!modParams.isFinite())
       mexErrMsgTxt("M_.params contains NaN or Inf");
 
-    const mxArray *param_names_mx = mxGetField(M_mx, 0, "param_names");
+    const mxArray* param_names_mx = mxGetField(M_mx, 0, "param_names");
     if (!(param_names_mx && mxIsCell(param_names_mx)))
       mexErrMsgTxt("M_.param_names should be a cell array");
     std::vector<std::string> paramNames = DynareMxArrayToString(param_names_mx);
@@ -171,10 +182,10 @@ extern "C" {
         return; // To silence a GCC warning about discount_factor unitialized
       }
 
-    const mxArray *sigma_e_mx = mxGetField(M_mx, 0, "Sigma_e");
+    const mxArray* sigma_e_mx = mxGetField(M_mx, 0, "Sigma_e");
     if (!(sigma_e_mx && mxIsDouble(sigma_e_mx) && mxGetM(sigma_e_mx) == mxGetN(sigma_e_mx)))
       mexErrMsgTxt("M_.Sigma_e should be a double precision square matrix");
-    TwoDMatrix vCov{ConstTwoDMatrix{sigma_e_mx}};
+    TwoDMatrix vCov {ConstTwoDMatrix {sigma_e_mx}};
     if (!vCov.isFinite())
       mexErrMsgTxt("M_.Sigma_e contains NaN or Inf");
 
@@ -187,65 +198,76 @@ extern "C" {
     const int nEndo = get_int_field(M_mx, "endo_nbr");
     const int nPar = get_int_field(M_mx, "param_nbr");
 
-    const mxArray *lead_lag_incidence_mx = mxGetField(M_mx, 0, "lead_lag_incidence");
-    if (!(lead_lag_incidence_mx && mxIsDouble(lead_lag_incidence_mx) && mxGetM(lead_lag_incidence_mx) == 3
+    const mxArray* lead_lag_incidence_mx = mxGetField(M_mx, 0, "lead_lag_incidence");
+    if (!(lead_lag_incidence_mx && mxIsDouble(lead_lag_incidence_mx)
+          && mxGetM(lead_lag_incidence_mx) == 3
           && mxGetN(lead_lag_incidence_mx) == static_cast<size_t>(nEndo)))
-      mexErrMsgTxt("M_.lead_lag_incidence should be a double precision matrix with 3 rows and M_.endo_nbr columns");
-    ConstTwoDMatrix llincidence{lead_lag_incidence_mx};
+      mexErrMsgTxt("M_.lead_lag_incidence should be a double precision matrix with 3 rows and "
+                   "M_.endo_nbr columns");
+    ConstTwoDMatrix llincidence {lead_lag_incidence_mx};
 
-    const mxArray *nnzderivatives_mx = mxGetField(M_mx, 0, "NNZDerivatives");
+    const mxArray* nnzderivatives_mx = mxGetField(M_mx, 0, "NNZDerivatives");
     if (!(nnzderivatives_mx && mxIsDouble(nnzderivatives_mx)))
       mexErrMsgTxt("M_.NNZDerivatives should be a double precision array");
-    ConstVector NNZD{nnzderivatives_mx};
-    if (NNZD.length() < kOrder || NNZD[kOrder-1] == -1)
-      mexErrMsgTxt("The derivatives were not computed for the required order. Make sure that you used the right order option inside the `stoch_simul' command");
-
-    const mxArray *nnzderivatives_obj_mx = mxGetField(M_mx, 0, "NNZDerivatives_objective");
-    if (!(nnzderivatives_obj_mx && mxIsDouble(nnzderivatives_obj_mx) && !mxIsComplex(nnzderivatives_obj_mx) && !mxIsSparse(nnzderivatives_obj_mx)))
+    ConstVector NNZD {nnzderivatives_mx};
+    if (NNZD.length() < kOrder || NNZD[kOrder - 1] == -1)
+      mexErrMsgTxt("The derivatives were not computed for the required order. Make sure that you "
+                   "used the right order option inside the `stoch_simul' command");
+
+    const mxArray* nnzderivatives_obj_mx = mxGetField(M_mx, 0, "NNZDerivatives_objective");
+    if (!(nnzderivatives_obj_mx && mxIsDouble(nnzderivatives_obj_mx)
+          && !mxIsComplex(nnzderivatives_obj_mx) && !mxIsSparse(nnzderivatives_obj_mx)))
       mexErrMsgTxt("M_.NNZDerivatives should be a real dense array");
-    ConstVector NNZD_obj{nnzderivatives_obj_mx};
-    if (NNZD.length() < kOrder || NNZD_obj[kOrder-1] == -1)
-      mexErrMsgTxt("The derivatives were not computed for the required order. Make sure that you used the right order option inside the `stoch_simul' command");
-
-    const mxArray *endo_names_mx = mxGetField(M_mx, 0, "endo_names");
-    if (!(endo_names_mx && mxIsCell(endo_names_mx) && mxGetNumberOfElements(endo_names_mx) == static_cast<size_t>(nEndo)))
+    ConstVector NNZD_obj {nnzderivatives_obj_mx};
+    if (NNZD.length() < kOrder || NNZD_obj[kOrder - 1] == -1)
+      mexErrMsgTxt("The derivatives were not computed for the required order. Make sure that you "
+                   "used the right order option inside the `stoch_simul' command");
+
+    const mxArray* endo_names_mx = mxGetField(M_mx, 0, "endo_names");
+    if (!(endo_names_mx && mxIsCell(endo_names_mx)
+          && mxGetNumberOfElements(endo_names_mx) == static_cast<size_t>(nEndo)))
       mexErrMsgTxt("M_.endo_names should be a cell array of M_.endo_nbr elements");
     std::vector<std::string> endoNames = DynareMxArrayToString(endo_names_mx);
 
-    const mxArray *exo_names_mx = mxGetField(M_mx, 0, "exo_names");
-    if (!(exo_names_mx && mxIsCell(exo_names_mx) && mxGetNumberOfElements(exo_names_mx) == static_cast<size_t>(nExog)))
+    const mxArray* exo_names_mx = mxGetField(M_mx, 0, "exo_names");
+    if (!(exo_names_mx && mxIsCell(exo_names_mx)
+          && mxGetNumberOfElements(exo_names_mx) == static_cast<size_t>(nExog)))
       mexErrMsgTxt("M_.exo_names should be a cell array of M_.exo_nbr elements");
     std::vector<std::string> exoNames = DynareMxArrayToString(exo_names_mx);
 
-    const mxArray *dynamic_tmp_nbr_mx = mxGetField(M_mx, 0, "dynamic_tmp_nbr");
+    const mxArray* dynamic_tmp_nbr_mx = mxGetField(M_mx, 0, "dynamic_tmp_nbr");
     if (!(dynamic_tmp_nbr_mx && mxIsDouble(dynamic_tmp_nbr_mx) && !mxIsComplex(dynamic_tmp_nbr_mx)
-          && !mxIsSparse(dynamic_tmp_nbr_mx) && mxGetNumberOfElements(dynamic_tmp_nbr_mx) >= static_cast<size_t>(kOrder+1)))
-      mexErrMsgTxt("M_.dynamic_tmp_nbr should be a double precision array with strictly more elements than the order of derivation");
-    int ntt = std::accumulate(mxGetPr(dynamic_tmp_nbr_mx), mxGetPr(dynamic_tmp_nbr_mx)+kOrder+1, 0);
+          && !mxIsSparse(dynamic_tmp_nbr_mx)
+          && mxGetNumberOfElements(dynamic_tmp_nbr_mx) >= static_cast<size_t>(kOrder + 1)))
+      mexErrMsgTxt("M_.dynamic_tmp_nbr should be a double precision array with strictly more "
+                   "elements than the order of derivation");
+    int ntt
+        = std::accumulate(mxGetPr(dynamic_tmp_nbr_mx), mxGetPr(dynamic_tmp_nbr_mx) + kOrder + 1, 0);
 
     // Extract various fields from dr
-    const mxArray *ys_mx = mxGetField(dr_mx, 0, "ys"); // and not in order of dr.order_var
+    const mxArray* ys_mx = mxGetField(dr_mx, 0, "ys"); // and not in order of dr.order_var
     if (!(ys_mx && mxIsDouble(ys_mx) && !mxIsComplex(ys_mx) && !mxIsSparse(ys_mx)))
       mexErrMsgTxt("dr.ys should be a real dense array");
-    Vector ySteady{ConstVector{ys_mx}};
+    Vector ySteady {ConstVector {ys_mx}};
     if (!ySteady.isFinite())
       mexErrMsgTxt("dr.ys contains NaN or Inf");
 
-    const mxArray *order_var_mx = mxGetField(dr_mx, 0, "order_var");
+    const mxArray* order_var_mx = mxGetField(dr_mx, 0, "order_var");
     if (!(order_var_mx && mxIsDouble(order_var_mx) && !mxIsComplex(order_var_mx)
           && !mxIsSparse(order_var_mx)
           && mxGetNumberOfElements(order_var_mx) == static_cast<size_t>(nEndo)))
       mexErrMsgTxt("dr.order_var should be a real dense array of M_.endo_nbr elements");
     std::vector<int> dr_order(nEndo);
-    std::transform(mxGetPr(order_var_mx), mxGetPr(order_var_mx)+nEndo, dr_order.begin(),
-                   [](double x) { return static_cast<int>(x)-1; });
+    std::transform(mxGetPr(order_var_mx), mxGetPr(order_var_mx) + nEndo, dr_order.begin(),
+                   [](double x) { return static_cast<int>(x) - 1; });
 
-    const int nSteps = 0; // Dynare++ solving steps, for time being default to 0 = deterministic steady state
+    const int nSteps
+        = 0; // Dynare++ solving steps, for time being default to 0 = deterministic steady state
 
     // Journal is not written on-disk, unless options_.debug = true (see #1735)
     Journal journal;
     if (debug)
-      journal = Journal{fname + ".jnl"};
+      journal = Journal {fname + ".jnl"};
 
     std::unique_ptr<DynamicModelAC> dynamicModelFile;
     if (use_dll)
@@ -254,31 +276,31 @@ extern "C" {
       dynamicModelFile = std::make_unique<DynamicModelMFile>(fname, ntt);
 
     // intiate tensor library
-    TLStatic::init(kOrder, nStat+2*nPred+3*nBoth+2*nForw+nExog);
+    TLStatic::init(kOrder, nStat + 2 * nPred + 3 * nBoth + 2 * nForw + nExog);
 
     // Set number of parallel threads
     sthread::detach_thread_group::max_parallel_threads = num_threads;
 
     // make KordpDynare object
-    KordpDynare dynare(endoNames, exoNames, nExog, nPar,
-                       ySteady, vCov, modParams, nStat, nPred, nForw, nBoth,
-                       NNZD, nSteps, kOrder, journal, std::move(dynamicModelFile),
+    KordpDynare dynare(endoNames, exoNames, nExog, nPar, ySteady, vCov, modParams, nStat, nPred,
+                       nForw, nBoth, NNZD, nSteps, kOrder, journal, std::move(dynamicModelFile),
                        dr_order, llincidence);
 
-
     // construct main K-order approximation class
     Approximation app(dynare, journal, nSteps, false, pruning, qz_criterium);
     // run stochastic steady
     app.walkStochSteady();
 
-    const mxArray *objective_tmp_nbr_mx = mxGetField(M_mx, 0, "objective_tmp_nbr");
+    const mxArray* objective_tmp_nbr_mx = mxGetField(M_mx, 0, "objective_tmp_nbr");
     if (!(objective_tmp_nbr_mx && mxIsDouble(objective_tmp_nbr_mx)
           && !mxIsComplex(objective_tmp_nbr_mx) && !mxIsSparse(objective_tmp_nbr_mx)
-          && mxGetNumberOfElements(objective_tmp_nbr_mx) >= static_cast<size_t>(kOrder+1)))
-      mexErrMsgTxt("M_.objective_tmp_nbr should be a real dense array with strictly more elements than the order of derivation");
-    int ntt_objective = std::accumulate(mxGetPr(objective_tmp_nbr_mx), mxGetPr(objective_tmp_nbr_mx)+kOrder+1, 0);
+          && mxGetNumberOfElements(objective_tmp_nbr_mx) >= static_cast<size_t>(kOrder + 1)))
+      mexErrMsgTxt("M_.objective_tmp_nbr should be a real dense array with strictly more elements "
+                   "than the order of derivation");
+    int ntt_objective = std::accumulate(mxGetPr(objective_tmp_nbr_mx),
+                                        mxGetPr(objective_tmp_nbr_mx) + kOrder + 1, 0);
 
-    //Getting derivatives of the planner's objective function
+    // Getting derivatives of the planner's objective function
     std::unique_ptr<ObjectiveAC> objectiveFile;
     objectiveFile = std::make_unique<ObjectiveMFile>(fname, ntt_objective);
 
@@ -286,25 +308,26 @@ extern "C" {
     KordwDynare welfare(dynare, NNZD_obj, journal, modParams, std::move(objectiveFile), dr_order);
 
     // construct main K-order approximation class of welfare
-    ApproximationWelfare appwel(welfare, discount_factor, app.get_rule_ders(), app.get_rule_ders_s(), journal);
+    ApproximationWelfare appwel(welfare, discount_factor, app.get_rule_ders(),
+                                app.get_rule_ders_s(), journal);
     appwel.approxAtSteady();
 
-    const FoldDecisionRule &cond_fdr = appwel.getFoldCondWel();
+    const FoldDecisionRule& cond_fdr = appwel.getFoldCondWel();
     // Add possibly missing field names
     for (int i = static_cast<int>(W_fieldnames.size()); i <= kOrder; i++)
       W_fieldnames.emplace_back("W_" + std::to_string(i));
     // Create structure for storing derivatives in Dynare++ format
-    const char *W_fieldnames_c[kOrder+1];
+    const char* W_fieldnames_c[kOrder + 1];
     for (int i = 0; i <= kOrder; i++)
       W_fieldnames_c[i] = W_fieldnames[i].c_str();
-    plhs[0] = mxCreateStructMatrix(1, 1, kOrder+1, W_fieldnames_c);
+    plhs[0] = mxCreateStructMatrix(1, 1, kOrder + 1, W_fieldnames_c);
 
     // Fill that structure
     for (int i = 0; i <= kOrder; i++)
       {
-        const FFSTensor &t = cond_fdr.get(Symmetry{i});
-        mxArray *tmp = mxCreateDoubleMatrix(t.nrows(), t.ncols(), mxREAL);
-        const ConstVector &vec = t.getData();
+        const FFSTensor& t = cond_fdr.get(Symmetry {i});
+        mxArray* tmp = mxCreateDoubleMatrix(t.nrows(), t.ncols(), mxREAL);
+        const ConstVector& vec = t.getData();
         assert(vec.skip() == 1);
         std::copy_n(vec.base(), vec.length(), mxGetPr(tmp));
         mxSetField(plhs[0], 0, ("W_" + std::to_string(i)).c_str(), tmp);
diff --git a/mex/sources/k_order_welfare/objective_abstract_class.hh b/mex/sources/k_order_welfare/objective_abstract_class.hh
index 868cf129fab1befe671c9c9fcaf54993dc5e158c..83a3ac98ac056eb8023fda48a48a702a2e689379 100644
--- a/mex/sources/k_order_welfare/objective_abstract_class.hh
+++ b/mex/sources/k_order_welfare/objective_abstract_class.hh
@@ -29,10 +29,10 @@ class ObjectiveAC
 protected:
   int ntt; // Size of vector of temporary terms
 public:
-  ObjectiveAC(int ntt_arg) : ntt{ntt_arg}
-  {
-  };
+  ObjectiveAC(int ntt_arg) : ntt {ntt_arg} {};
   virtual ~ObjectiveAC() = default;
-  virtual void eval(const Vector &y, const Vector &x, const Vector &params, Vector &residual, std::vector<TwoDMatrix> &md) = 0;
+  virtual void eval(const Vector& y, const Vector& x, const Vector& params, Vector& residual,
+                    std::vector<TwoDMatrix>& md)
+      = 0;
 };
 #endif
diff --git a/mex/sources/k_order_welfare/objective_m.cc b/mex/sources/k_order_welfare/objective_m.cc
index 758a013a30605cb3fc3dfd8594d47f8a99dcef50..1a34095f75bf48996e670bfa5cc04faa9d02cb3a 100644
--- a/mex/sources/k_order_welfare/objective_m.cc
+++ b/mex/sources/k_order_welfare/objective_m.cc
@@ -25,18 +25,17 @@
 
 #include "objective_m.hh"
 
-ObjectiveMFile::ObjectiveMFile(const std::string &modName, int ntt_arg) :
-  ObjectiveAC(ntt_arg),
-  ObjectiveMFilename{modName + ".objective.static"}
+ObjectiveMFile::ObjectiveMFile(const std::string& modName, int ntt_arg) :
+    ObjectiveAC(ntt_arg), ObjectiveMFilename {modName + ".objective.static"}
 {
 }
 
 void
-ObjectiveMFile::unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray *sparseMat, TwoDMatrix &tdm)
+ObjectiveMFile::unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray* sparseMat, TwoDMatrix& tdm)
 {
   int totalCols = mxGetN(sparseMat);
-  mwIndex *rowIdxVector = mxGetIr(sparseMat);
-  mwIndex *colIdxVector = mxGetJc(sparseMat);
+  mwIndex* rowIdxVector = mxGetIr(sparseMat);
+  mwIndex* colIdxVector = mxGetJc(sparseMat);
 
   assert(tdm.ncols() == 3);
   /* Under MATLAB, the following check always holds at equality; under Octave,
@@ -44,13 +43,13 @@ ObjectiveMFile::unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray *sparseMat, Two
      zeros in the values vector when calling sparse(). */
   assert(tdm.nrows() >= static_cast<int>(mxGetNzmax(sparseMat)));
 
-  double *ptr = mxGetPr(sparseMat);
+  double* ptr = mxGetPr(sparseMat);
 
   int rind = 0;
   int output_row = 0;
 
   for (int i = 0; i < totalCols; i++)
-    for (int j = 0; j < static_cast<int>((colIdxVector[i+1]-colIdxVector[i])); j++, rind++)
+    for (int j = 0; j < static_cast<int>((colIdxVector[i + 1] - colIdxVector[i])); j++, rind++)
       {
         tdm.get(output_row, 0) = rowIdxVector[rind] + 1;
         tdm.get(output_row, 1) = i + 1;
@@ -72,28 +71,29 @@ ObjectiveMFile::unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray *sparseMat, Two
 }
 
 void
-ObjectiveMFile::eval(const Vector &y, const Vector &x, const Vector &modParams,
-                     Vector &residual, std::vector<TwoDMatrix> &md) noexcept(false)
+ObjectiveMFile::eval(const Vector& y, const Vector& x, const Vector& modParams, Vector& residual,
+                     std::vector<TwoDMatrix>& md) noexcept(false)
 {
-  mxArray *T_m = mxCreateDoubleMatrix(ntt, 1, mxREAL);
+  mxArray* T_m = mxCreateDoubleMatrix(ntt, 1, mxREAL);
 
-  mxArray *y_m = mxCreateDoubleMatrix(y.length(), 1, mxREAL);
+  mxArray* y_m = mxCreateDoubleMatrix(y.length(), 1, mxREAL);
   std::copy_n(y.base(), y.length(), mxGetPr(y_m));
 
-  mxArray *x_m = mxCreateDoubleMatrix(1, x.length(), mxREAL);
+  mxArray* x_m = mxCreateDoubleMatrix(1, x.length(), mxREAL);
   std::copy_n(x.base(), x.length(), mxGetPr(x_m));
 
-  mxArray *params_m = mxCreateDoubleMatrix(modParams.length(), 1, mxREAL);
+  mxArray* params_m = mxCreateDoubleMatrix(modParams.length(), 1, mxREAL);
   std::copy_n(modParams.base(), modParams.length(), mxGetPr(params_m));
 
-  mxArray *T_flag_m = mxCreateLogicalScalar(false);
+  mxArray* T_flag_m = mxCreateLogicalScalar(false);
 
   {
     // Compute temporary terms (for all orders)
     std::string funcname = ObjectiveMFilename + "_g" + std::to_string(md.size()) + "_tt";
-    mxArray *plhs[1], *prhs[] = { T_m, y_m, x_m, params_m };
+    mxArray *plhs[1], *prhs[] = {T_m, y_m, x_m, params_m};
 
-    int retVal = mexCallMATLAB(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>, prhs, funcname.c_str());
+    int retVal = mexCallMATLAB(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>,
+                               prhs, funcname.c_str());
     if (retVal != 0)
       throw DynareException(__FILE__, __LINE__, "Trouble calling " + funcname);
 
@@ -104,13 +104,14 @@ ObjectiveMFile::eval(const Vector &y, const Vector &x, const Vector &modParams,
   {
     // Compute residuals
     std::string funcname = ObjectiveMFilename + "_resid";
-    mxArray *plhs[1], *prhs[] = { T_m, y_m, x_m, params_m, T_flag_m };
+    mxArray *plhs[1], *prhs[] = {T_m, y_m, x_m, params_m, T_flag_m};
 
-    int retVal = mexCallMATLAB(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>, prhs, funcname.c_str());
+    int retVal = mexCallMATLAB(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>,
+                               prhs, funcname.c_str());
     if (retVal != 0)
       throw DynareException(__FILE__, __LINE__, "Trouble calling " + funcname);
 
-    residual = Vector{plhs[0]};
+    residual = Vector {plhs[0]};
     mxDestroyArray(plhs[0]);
   }
 
@@ -118,20 +119,21 @@ ObjectiveMFile::eval(const Vector &y, const Vector &x, const Vector &modParams,
     {
       // Compute model derivatives
       std::string funcname = ObjectiveMFilename + "_g" + std::to_string(i);
-      mxArray *plhs[1], *prhs[] = { T_m, y_m, x_m, params_m, T_flag_m };
+      mxArray *plhs[1], *prhs[] = {T_m, y_m, x_m, params_m, T_flag_m};
 
-      int retVal = mexCallMATLAB(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>, prhs, funcname.c_str());
+      int retVal = mexCallMATLAB(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>,
+                                 prhs, funcname.c_str());
       if (retVal != 0)
         throw DynareException(__FILE__, __LINE__, "Trouble calling " + funcname);
 
       if (i == 1)
         {
-          assert(static_cast<int>(mxGetM(plhs[0])) == md[i-1].nrows());
-          assert(static_cast<int>(mxGetN(plhs[0])) == md[i-1].ncols());
-          std::copy_n(mxGetPr(plhs[0]), mxGetM(plhs[0])*mxGetN(plhs[0]), md[i-1].base());
+          assert(static_cast<int>(mxGetM(plhs[0])) == md[i - 1].nrows());
+          assert(static_cast<int>(mxGetN(plhs[0])) == md[i - 1].ncols());
+          std::copy_n(mxGetPr(plhs[0]), mxGetM(plhs[0]) * mxGetN(plhs[0]), md[i - 1].base());
         }
       else
-        unpackSparseMatrixAndCopyIntoTwoDMatData(plhs[0], md[i-1]);
+        unpackSparseMatrixAndCopyIntoTwoDMatData(plhs[0], md[i - 1]);
 
       mxDestroyArray(plhs[0]);
     }
diff --git a/mex/sources/k_order_welfare/objective_m.hh b/mex/sources/k_order_welfare/objective_m.hh
index 16eefb2db6bb94ef463001656b1ac6d8ce9cc470..0e999c26d8c4a9f995691a916a4cd36d2a2818a4 100644
--- a/mex/sources/k_order_welfare/objective_m.hh
+++ b/mex/sources/k_order_welfare/objective_m.hh
@@ -33,11 +33,12 @@ class ObjectiveMFile : public ObjectiveAC
 {
 private:
   const std::string ObjectiveMFilename;
-  static void unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray *sparseMat, TwoDMatrix &tdm);
+  static void unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray* sparseMat, TwoDMatrix& tdm);
+
 public:
-  explicit ObjectiveMFile(const std::string &modName, int ntt_arg);
+  explicit ObjectiveMFile(const std::string& modName, int ntt_arg);
   virtual ~ObjectiveMFile() = default;
-  void eval(const Vector &y, const Vector &x, const Vector &params,
-            Vector &residual, std::vector<TwoDMatrix> &md) override;
+  void eval(const Vector& y, const Vector& x, const Vector& params, Vector& residual,
+            std::vector<TwoDMatrix>& md) override;
 };
 #endif
diff --git a/mex/sources/kalman_steady_state/kalman_steady_state.cc b/mex/sources/kalman_steady_state/kalman_steady_state.cc
index 50aa8354dc011d626670a669e8f8b4d2f2078c15..dd4446e000a0df31f74e1c746e8cb7f7c4e5ab46 100644
--- a/mex/sources/kalman_steady_state/kalman_steady_state.cc
+++ b/mex/sources/kalman_steady_state/kalman_steady_state.cc
@@ -26,7 +26,8 @@
   ++
   ++      [0]  T       (double)   n×n transition matrix.
   ++
-  ++      [1]  QQ      (double)   n×n matrix (=R·Q·Rᵀ, where Q is the covariance matrix of the structural innovations).
+  ++      [1]  QQ      (double)   n×n matrix (=R·Q·Rᵀ, where Q is the covariance matrix of the
+  structural innovations).
   ++
   ++      [2]  Z       (double)   n×p selection matrix.
   ++
@@ -49,9 +50,9 @@
 */
 
 #include <algorithm>
-#include <memory>
-#include <dynmex.h>
 #include <dynlapack.h>
+#include <dynmex.h>
+#include <memory>
 
 #define sb02od FORTRAN_WRAPPER(sb02od)
 
@@ -59,19 +60,19 @@ extern "C"
 {
   /* Note: matrices q, r and l may be modified internally (though they are
      restored on exit), hence their pointers are not declared as const */
-  int sb02od(const char *dico, const char *jobb, const char *fact, const char *uplo,
-             const char *jobl, const char *sort, const lapack_int *n, const lapack_int *m,
-             const lapack_int *p, const double *a, const lapack_int *lda, const double *b,
-             const lapack_int *ldb, double *q, const lapack_int *ldq, double *r, const lapack_int *ldr,
-             double *l, const lapack_int *ldl, double *rcond, double *x, const lapack_int *ldx,
-             double *alfar, double *alfai, double *beta, double *s, const lapack_int *lds, double *t,
-             const lapack_int *ldt, double *u, const lapack_int *ldu, const double *tol,
-             lapack_int *iwork, double *dwork, const lapack_int *ldwork, lapack_int *bwork,
-             lapack_int *info);
+  int sb02od(const char* dico, const char* jobb, const char* fact, const char* uplo,
+             const char* jobl, const char* sort, const lapack_int* n, const lapack_int* m,
+             const lapack_int* p, const double* a, const lapack_int* lda, const double* b,
+             const lapack_int* ldb, double* q, const lapack_int* ldq, double* r,
+             const lapack_int* ldr, double* l, const lapack_int* ldl, double* rcond, double* x,
+             const lapack_int* ldx, double* alfar, double* alfai, double* beta, double* s,
+             const lapack_int* lds, double* t, const lapack_int* ldt, double* u,
+             const lapack_int* ldu, const double* tol, lapack_int* iwork, double* dwork,
+             const lapack_int* ldwork, lapack_int* bwork, lapack_int* info);
 }
 
 void
-mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
+mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
 {
   // Check the number of arguments and set some flags.
   bool measurement_error_flag = true;
@@ -97,10 +98,12 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
   if (mxIsNumeric(prhs[1]) == 0 || mxIsComplex(prhs[1]) == 1)
     mexErrMsgTxt("kalman_steady_state: The second input argument (QQ) must be a real matrix!");
   if (q != n)
-    mexErrMsgTxt("kalman_steady_state: The size of the second input argument (QQ) must match the size of the first argument (T)!");
+    mexErrMsgTxt("kalman_steady_state: The size of the second input argument (QQ) must match the "
+                 "size of the first argument (T)!");
   lapack_int p = mxGetN(prhs[2]);
   if (mxGetM(prhs[2]) != static_cast<size_t>(n))
-    mexErrMsgTxt("kalman_steady_state: The number of rows of the third argument (Z) must match the number of rows of the first argument (T)!");
+    mexErrMsgTxt("kalman_steady_state: The number of rows of the third argument (Z) must match the "
+                 "number of rows of the first argument (T)!");
   if (mxIsNumeric(prhs[2]) == 0 || mxIsComplex(prhs[2]) == 1)
     mexErrMsgTxt("kalman_steady_state: The third input argument (Z) must be a real matrix!");
   if (measurement_error_flag)
@@ -108,30 +111,35 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
       if (mxGetM(prhs[3]) != mxGetN(prhs[3]))
         mexErrMsgTxt("kalman_steady_state: The fourth input argument (H) must be a square matrix!");
       if (mxGetM(prhs[3]) != static_cast<size_t>(p))
-        mexErrMsgTxt("kalman_steady_state: The number of rows of the fourth input argument (H) must match the number of rows of the third input argument!");
+        mexErrMsgTxt("kalman_steady_state: The number of rows of the fourth input argument (H) "
+                     "must match the number of rows of the third input argument!");
       if (mxIsNumeric(prhs[3]) == 0 || mxIsComplex(prhs[3]) == 1)
         mexErrMsgTxt("kalman_steady_state: The fifth input argument (H) must be a real matrix!");
     }
   // Get input matrices.
-  const double *T = mxGetPr(prhs[0]);
-  auto QQ = std::make_unique<double[]>(n*n);
-  std::copy_n(mxGetPr(prhs[1]), n*n, QQ.get());
-  const double *Z = mxGetPr(prhs[2]);
-  auto H = std::make_unique<double[]>(p*p);
+  const double* T = mxGetPr(prhs[0]);
+  auto QQ = std::make_unique<double[]>(n * n);
+  std::copy_n(mxGetPr(prhs[1]), n * n, QQ.get());
+  const double* Z = mxGetPr(prhs[2]);
+  auto H = std::make_unique<double[]>(p * p);
   if (measurement_error_flag)
-    std::copy_n(mxGetPr(prhs[3]), p*p, H.get());
+    std::copy_n(mxGetPr(prhs[3]), p * p, H.get());
   // L will not be used.
-  auto L = std::make_unique<double[]>(n*p);
-  lapack_int nn = 2*n;
+  auto L = std::make_unique<double[]>(n * p);
+  lapack_int nn = 2 * n;
   lapack_int LDA = std::max(static_cast<lapack_int>(1), n);
   lapack_int LDQ = LDA;
   lapack_int LDU = std::max(static_cast<lapack_int>(1), nn);
-  lapack_int LDS = std::max(static_cast<lapack_int>(1), nn+p);
+  lapack_int LDS = std::max(static_cast<lapack_int>(1), nn + p);
   lapack_int LIWORK = std::max(static_cast<lapack_int>(1), std::max(p, nn));
   lapack_int LDR = std::max(static_cast<lapack_int>(1), p);
   lapack_int LDB = LDA, LDL = LDA, LDT = LDS, LDX = LDA;
-  lapack_int LDWORK = std::max(static_cast<lapack_int>(7)*(static_cast<lapack_int>(2)*n + static_cast<lapack_int>(1)) + static_cast<lapack_int>(16), static_cast<lapack_int>(16)*n);
-  LDWORK = std::max(LDWORK, std::max(static_cast<lapack_int>(2)*n + p, static_cast<lapack_int>(3)*p));
+  lapack_int LDWORK = std::max(
+      static_cast<lapack_int>(7) * (static_cast<lapack_int>(2) * n + static_cast<lapack_int>(1))
+          + static_cast<lapack_int>(16),
+      static_cast<lapack_int>(16) * n);
+  LDWORK = std::max(LDWORK,
+                    std::max(static_cast<lapack_int>(2) * n + p, static_cast<lapack_int>(3) * p));
   double tolerance = 1e-16;
   lapack_int INFO;
   // Outputs of subroutine sb02OD
@@ -139,16 +147,16 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
   auto WR = std::make_unique<double[]>(nn);
   auto WI = std::make_unique<double[]>(nn);
   auto BETA = std::make_unique<double[]>(nn);
-  auto S = std::make_unique<double[]>(LDS*(nn+p));
-  auto TT = std::make_unique<double[]>(LDT*nn);
-  auto UU = std::make_unique<double[]>(LDU*nn);
+  auto S = std::make_unique<double[]>(LDS * (nn + p));
+  auto TT = std::make_unique<double[]>(LDT * nn);
+  auto UU = std::make_unique<double[]>(LDU * nn);
   // Working arrays
   auto IWORK = std::make_unique<lapack_int[]>(LIWORK);
   auto DWORK = std::make_unique<double[]>(LDWORK);
   auto BWORK = std::make_unique<lapack_int[]>(nn);
   // Initialize the output of the mex file
   plhs[0] = mxCreateDoubleMatrix(n, n, mxREAL);
-  double *P = mxGetPr(plhs[0]);
+  double* P = mxGetPr(plhs[0]);
   // Call the slicot routine
   sb02od("D", // We want to solve a discrete Riccati equation.
          "B", // Matrices Z and H are given.
@@ -156,15 +164,16 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
          "U", // Upper triangle of matrix H is stored.
          "Z", // L matrix is zero.
          "S", // Stable eigenvalues come first.
-         &n, &p, &p, T, &LDA, Z, &LDB, QQ.get(), &LDQ, H.get(), &LDR, L.get(), &LDL,
-         &rcond, P, &LDX, WR.get(), WI.get(), BETA.get(), S.get(), &LDS, TT.get(), &LDT, UU.get(),
-         &LDU, &tolerance, IWORK.get(), DWORK.get(), &LDWORK, BWORK.get(), &INFO);
+         &n, &p, &p, T, &LDA, Z, &LDB, QQ.get(), &LDQ, H.get(), &LDR, L.get(), &LDL, &rcond, P,
+         &LDX, WR.get(), WI.get(), BETA.get(), S.get(), &LDS, TT.get(), &LDT, UU.get(), &LDU,
+         &tolerance, IWORK.get(), DWORK.get(), &LDWORK, BWORK.get(), &INFO);
   switch (INFO)
     {
     case 0:
       break;
     case 1:
-      mexErrMsgTxt("The computed extended matrix pencil is singular, possibly due to rounding errors.");
+      mexErrMsgTxt(
+          "The computed extended matrix pencil is singular, possibly due to rounding errors.");
       break;
     case 2:
       mexErrMsgTxt("The QZ (or QR) algorithm failed!");
@@ -173,13 +182,16 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
       mexErrMsgTxt("The reordering of the (generalized) eigenvalues failed!");
       break;
     case 4:
-      mexErrMsgTxt("After reordering, roundoff changed values of some complex eigenvalues so that leading eigenvalues\n in the (generalized) Schur form no longer satisfy the stability condition; this could also be caused due to scaling.");
+      mexErrMsgTxt("After reordering, roundoff changed values of some complex eigenvalues so that "
+                   "leading eigenvalues\n in the (generalized) Schur form no longer satisfy the "
+                   "stability condition; this could also be caused due to scaling.");
       break;
     case 5:
       mexErrMsgTxt("The computed dimension of the solution does not equal n!");
       break;
     case 6:
-      mexErrMsgTxt("A singular matrix was encountered during the computation of the solution matrix P!");
+      mexErrMsgTxt(
+          "A singular matrix was encountered during the computation of the solution matrix P!");
       break;
     default:
       mexErrMsgTxt("Unknown problem!");
diff --git a/mex/sources/kronecker/sparse_hessian_times_B_kronecker_C.cc b/mex/sources/kronecker/sparse_hessian_times_B_kronecker_C.cc
index 0b88faf5845cb565d46547f707bc53ad30b8100a..a67186baaeb69549244f5d419fad1bf5bfa8d27d 100644
--- a/mex/sources/kronecker/sparse_hessian_times_B_kronecker_C.cc
+++ b/mex/sources/kronecker/sparse_hessian_times_B_kronecker_C.cc
@@ -19,8 +19,8 @@
 
 /*
  * This mex file computes A·(B⊗C) or A·(B⊗B) without explicitly building B⊗C or B⊗B, so that
- * one can consider large matrices A, B and/or C, and assuming that A is a the hessian of a DSGE model
- * (dynare format). This mex file should not be used outside dyn_second_order_solver.m.
+ * one can consider large matrices A, B and/or C, and assuming that A is a the hessian of a DSGE
+ * model (dynare format). This mex file should not be used outside dyn_second_order_solver.m.
  */
 
 #include <algorithm>
@@ -32,8 +32,9 @@
 #define DEBUG_OMP 0
 
 void
-sparse_hessian_times_B_kronecker_B(const mwIndex *isparseA, const mwIndex *jsparseA, const double *vsparseA,
-                                   const double *B, double *D, size_t mA, size_t nA, size_t mB, size_t nB, int number_of_threads)
+sparse_hessian_times_B_kronecker_B(const mwIndex* isparseA, const mwIndex* jsparseA,
+                                   const double* vsparseA, const double* B, double* D, size_t mA,
+                                   size_t nA, size_t mB, size_t nB, int number_of_threads)
 {
   /*
   **   Loop over the columns of B⊗B (or of the result matrix D).
@@ -48,7 +49,7 @@ sparse_hessian_times_B_kronecker_B(const mwIndex *isparseA, const mwIndex *jspar
 #endif
       for (mwIndex j2B = j1B; j2B < static_cast<mwIndex>(nB); j2B++)
         {
-          mwIndex jj = j1B*nB+j2B; // column of B⊗B index.
+          mwIndex jj = j1B * nB + j2B; // column of B⊗B index.
           mwIndex iv = 0;
           int nz_in_column_ii_of_A = 0;
           mwIndex k1 = 0;
@@ -59,47 +60,49 @@ sparse_hessian_times_B_kronecker_B(const mwIndex *isparseA, const mwIndex *jspar
           for (mwIndex ii = 0; ii < static_cast<mwIndex>(nA); ii++)
             {
               k1 = jsparseA[ii];
-              k2 = jsparseA[ii+1];
-              if (k1 < k2) // otherwise column ii of A does not have non zero elements (and there is nothing to compute).
+              k2 = jsparseA[ii + 1];
+              if (k1 < k2) // otherwise column ii of A does not have non zero elements (and there is
+                           // nothing to compute).
                 {
                   ++nz_in_column_ii_of_A;
                   mwIndex i1B = ii / mB;
                   mwIndex i2B = ii % mB;
-                  double bb = B[j1B*mB+i1B]*B[j2B*mB+i2B];
+                  double bb = B[j1B * mB + i1B] * B[j2B * mB + i2B];
                   /*
                   ** Loop over the non zero entries of A(:,ii).
                   */
                   for (mwIndex k = k1; k < k2; k++)
                     {
                       mwIndex kk = isparseA[k];
-                      D[jj*mA+kk] = D[jj*mA+kk] + bb*vsparseA[iv];
+                      D[jj * mA + kk] = D[jj * mA + kk] + bb * vsparseA[iv];
                       iv++;
                     }
                 }
             }
           if (nz_in_column_ii_of_A > 0)
-            std::copy_n(&D[jj*mA], mA, &D[(j2B*nB+j1B)*mA]);
+            std::copy_n(&D[jj * mA], mA, &D[(j2B * nB + j1B) * mA]);
         }
     }
 }
 
 void
-sparse_hessian_times_B_kronecker_C(const mwIndex *isparseA, const mwIndex *jsparseA, const double *vsparseA,
-                                   const double *B, const double *C, double *D,
-                                   size_t mA, size_t nA, size_t mB, size_t nB, size_t mC, size_t nC, int number_of_threads)
+sparse_hessian_times_B_kronecker_C(const mwIndex* isparseA, const mwIndex* jsparseA,
+                                   const double* vsparseA, const double* B, const double* C,
+                                   double* D, size_t mA, size_t nA, size_t mB, size_t nB, size_t mC,
+                                   size_t nC, int number_of_threads)
 {
   /*
   **   Loop over the columns of B⊗B (or of the result matrix D).
   */
 #pragma omp parallel for num_threads(number_of_threads)
-  for (mwIndex jj = 0; jj < static_cast<mwIndex>(nB*nC); jj++) // column of B⊗C index.
+  for (mwIndex jj = 0; jj < static_cast<mwIndex>(nB * nC); jj++) // column of B⊗C index.
     {
       // Uncomment the following line to check if all processors are used.
 #if DEBUG_OMP
       mexPrintf("%d thread number is %d (%d).\n", jj, omp_get_thread_num(), omp_get_num_threads());
 #endif
-      mwIndex jB = jj/nC;
-      mwIndex jC = jj%nC;
+      mwIndex jB = jj / nC;
+      mwIndex jC = jj % nC;
       mwIndex k1 = 0;
       mwIndex k2 = 0;
       mwIndex iv = 0;
@@ -110,20 +113,21 @@ sparse_hessian_times_B_kronecker_C(const mwIndex *isparseA, const mwIndex *jspar
       for (mwIndex ii = 0; ii < static_cast<mwIndex>(nA); ii++)
         {
           k1 = jsparseA[ii];
-          k2 = jsparseA[ii+1];
-          if (k1 < k2) // otherwise column ii of A does not have non zero elements (and there is nothing to compute).
+          k2 = jsparseA[ii + 1];
+          if (k1 < k2) // otherwise column ii of A does not have non zero elements (and there is
+                       // nothing to compute).
             {
               ++nz_in_column_ii_of_A;
               mwIndex iC = ii % mC;
               mwIndex iB = ii / mC;
-              double cb = C[jC*mC+iC]*B[jB*mB+iB];
+              double cb = C[jC * mC + iC] * B[jB * mB + iB];
               /*
               ** Loop over the non zero entries of A(:,ii).
               */
               for (mwIndex k = k1; k < k2; k++)
                 {
                   mwIndex kk = isparseA[k];
-                  D[jj*mA+kk] = D[jj*mA+kk] + cb*vsparseA[iv];
+                  D[jj * mA + kk] = D[jj * mA + kk] + cb * vsparseA[iv];
                   iv++;
                 }
             }
@@ -132,12 +136,13 @@ sparse_hessian_times_B_kronecker_C(const mwIndex *isparseA, const mwIndex *jspar
 }
 
 void
-mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
+mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
 {
   // Check input and output:
   if (nrhs > 4 || nrhs < 3 || nlhs != 1)
     {
-      mexErrMsgTxt("sparse_hessian_times_B_kronecker_C takes 3 or 4 input arguments and provides 1 output argument.");
+      mexErrMsgTxt("sparse_hessian_times_B_kronecker_C takes 3 or 4 input arguments and provides 1 "
+                   "output argument.");
       return; // Needed to shut up some GCC warnings
     }
 
@@ -158,19 +163,19 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
     {
       mC = mxGetM(prhs[2]);
       nC = mxGetN(prhs[2]);
-      if (mB*mC != nA)
+      if (mB * mC != nA)
         mexErrMsgTxt("Input dimension error!");
     }
   else // A·(B⊗B) is to be computed.
     {
-      if (mB*mB != nA)
+      if (mB * mB != nA)
         mexErrMsgTxt("Input dimension error!");
     }
   // Get input matrices:
   int numthreads;
-  const double *B = mxGetPr(prhs[1]);
-  const double *C;
-  const mxArray *numthreads_mx;
+  const double* B = mxGetPr(prhs[1]);
+  const double* C;
+  const mxArray* numthreads_mx;
   if (nrhs == 4)
     {
       C = mxGetPr(prhs[2]);
@@ -186,19 +191,21 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
     mexErrMsgTxt("sparse_hessian_times_B_kronecker_C: Last input must be a positive integer.");
 
   // Sparse (dynare) hessian matrix.
-  const mwIndex *isparseA = mxGetIr(prhs[0]);
-  const mwIndex *jsparseA = mxGetJc(prhs[0]);
-  const double *vsparseA = mxGetPr(prhs[0]);
+  const mwIndex* isparseA = mxGetIr(prhs[0]);
+  const mwIndex* jsparseA = mxGetJc(prhs[0]);
+  const double* vsparseA = mxGetPr(prhs[0]);
   // Initialization of the ouput:
   if (nrhs == 4)
-    plhs[0] = mxCreateDoubleMatrix(mA, nB*nC, mxREAL);
+    plhs[0] = mxCreateDoubleMatrix(mA, nB * nC, mxREAL);
   else
-    plhs[0] = mxCreateDoubleMatrix(mA, nB*nB, mxREAL);
-  double *D = mxGetPr(plhs[0]);
+    plhs[0] = mxCreateDoubleMatrix(mA, nB * nB, mxREAL);
+  double* D = mxGetPr(plhs[0]);
 
   // Computational part:
   if (nrhs == 3)
-    sparse_hessian_times_B_kronecker_B(isparseA, jsparseA, vsparseA, B, D, mA, nA, mB, nB, numthreads);
+    sparse_hessian_times_B_kronecker_B(isparseA, jsparseA, vsparseA, B, D, mA, nA, mB, nB,
+                                       numthreads);
   else
-    sparse_hessian_times_B_kronecker_C(isparseA, jsparseA, vsparseA, B, C, D, mA, nA, mB, nB, mC, nC, numthreads);
+    sparse_hessian_times_B_kronecker_C(isparseA, jsparseA, vsparseA, B, C, D, mA, nA, mB, nB, mC,
+                                       nC, numthreads);
 }
diff --git a/mex/sources/libkorder/dynamic_abstract_class.hh b/mex/sources/libkorder/dynamic_abstract_class.hh
index eed772c56561c58ff3120606ea79525d87fa9115..b4928010dcb1968bdc03d43623ebf6384057ec0d 100644
--- a/mex/sources/libkorder/dynamic_abstract_class.hh
+++ b/mex/sources/libkorder/dynamic_abstract_class.hh
@@ -29,11 +29,10 @@ class DynamicModelAC
 protected:
   int ntt; // Size of vector of temporary terms
 public:
-  DynamicModelAC(int ntt_arg) : ntt{ntt_arg}
-  {
-  };
+  DynamicModelAC(int ntt_arg) : ntt {ntt_arg} {};
   virtual ~DynamicModelAC() = default;
-  virtual void eval(const Vector &y, const Vector &x, const Vector &params, const Vector &ySteady,
-                    Vector &residual, std::vector<TwoDMatrix> &md) = 0;
+  virtual void eval(const Vector& y, const Vector& x, const Vector& params, const Vector& ySteady,
+                    Vector& residual, std::vector<TwoDMatrix>& md)
+      = 0;
 };
 #endif
diff --git a/mex/sources/libkorder/dynamic_dll.cc b/mex/sources/libkorder/dynamic_dll.cc
index afd732c3c7445863da7af2e4ab860b18f17c7580..4876b729b6499ba063949d799a4aeeba283b6e5b 100644
--- a/mex/sources/libkorder/dynamic_dll.cc
+++ b/mex/sources/libkorder/dynamic_dll.cc
@@ -19,11 +19,11 @@
 
 #include "dynamic_dll.hh"
 
-#include <iostream>
 #include <cassert>
+#include <iostream>
 
-DynamicModelDLL::DynamicModelDLL(const std::string &modName, int ntt_arg, int order)
-  : DynamicModelAC(ntt_arg)
+DynamicModelDLL::DynamicModelDLL(const std::string& modName, int ntt_arg, int order) :
+    DynamicModelAC(ntt_arg)
 {
   std::string fName;
 #if !defined(__CYGWIN32__) && !defined(_WIN32)
@@ -37,20 +37,24 @@ DynamicModelDLL::DynamicModelDLL(const std::string &modName, int ntt_arg, int or
   dynamicHinstance = dlopen(fName.c_str(), RTLD_NOW);
 #endif
   if (!dynamicHinstance)
-    throw DynareException(__FILE__, __LINE__, "Error when loading " + fName
+    throw DynareException(__FILE__, __LINE__,
+                          "Error when loading " + fName
 #if !defined(__CYGWIN32__) && !defined(_WIN32)
-                          + ": " + dlerror()
+                              + ": " + dlerror()
 #endif
-                          );
+    );
 
-  dynamic_tt.resize(order+1);
+  dynamic_tt.resize(order + 1);
 
-  std::tie(dynamic_resid, dynamic_tt[0]) = getSymbolsFromDLL<dynamic_resid_or_g1_fct>("dynamic_resid", fName);
-  std::tie(dynamic_g1, dynamic_tt[1]) = getSymbolsFromDLL<dynamic_resid_or_g1_fct>("dynamic_g1", fName);
+  std::tie(dynamic_resid, dynamic_tt[0])
+      = getSymbolsFromDLL<dynamic_resid_or_g1_fct>("dynamic_resid", fName);
+  std::tie(dynamic_g1, dynamic_tt[1])
+      = getSymbolsFromDLL<dynamic_resid_or_g1_fct>("dynamic_g1", fName);
 
-  dynamic_higher_deriv.resize(std::max(0, order-1));
+  dynamic_higher_deriv.resize(std::max(0, order - 1));
   for (int i = 2; i <= order; i++)
-    std::tie(dynamic_higher_deriv[i-2], dynamic_tt[i]) = getSymbolsFromDLL<dynamic_higher_deriv_fct>("dynamic_g" + std::to_string(i), fName);
+    std::tie(dynamic_higher_deriv[i - 2], dynamic_tt[i])
+        = getSymbolsFromDLL<dynamic_higher_deriv_fct>("dynamic_g" + std::to_string(i), fName);
 
   tt = std::make_unique<double[]>(ntt);
 }
@@ -70,19 +74,24 @@ DynamicModelDLL::~DynamicModelDLL()
 }
 
 void
-DynamicModelDLL::eval(const Vector &y, const Vector &x, const Vector &modParams, const Vector &ySteady,
-                      Vector &residual, std::vector<TwoDMatrix> &md) noexcept(false)
+DynamicModelDLL::eval(const Vector& y, const Vector& x, const Vector& modParams,
+                      const Vector& ySteady, Vector& residual,
+                      std::vector<TwoDMatrix>& md) noexcept(false)
 {
-  assert(md.size() == dynamic_tt.size()-1);
+  assert(md.size() == dynamic_tt.size() - 1);
 
   for (size_t i = 0; i < dynamic_tt.size(); i++)
     {
       dynamic_tt[i](y.base(), x.base(), 1, modParams.base(), ySteady.base(), 0, tt.get());
       if (i == 0)
-        dynamic_resid(y.base(), x.base(), 1, modParams.base(), ySteady.base(), 0, tt.get(), residual.base());
+        dynamic_resid(y.base(), x.base(), 1, modParams.base(), ySteady.base(), 0, tt.get(),
+                      residual.base());
       else if (i == 1)
-        dynamic_g1(y.base(), x.base(), 1, modParams.base(), ySteady.base(), 0, tt.get(), md[0].base());
+        dynamic_g1(y.base(), x.base(), 1, modParams.base(), ySteady.base(), 0, tt.get(),
+                   md[0].base());
       else
-        dynamic_higher_deriv[i-2](y.base(), x.base(), 1, modParams.base(), ySteady.base(), 0, tt.get(), &md[i-1].get(0, 0), &md[i-1].get(0, 1), &md[i-1].get(0, 2));
+        dynamic_higher_deriv[i - 2](y.base(), x.base(), 1, modParams.base(), ySteady.base(), 0,
+                                    tt.get(), &md[i - 1].get(0, 0), &md[i - 1].get(0, 1),
+                                    &md[i - 1].get(0, 2));
     }
 }
diff --git a/mex/sources/libkorder/dynamic_dll.hh b/mex/sources/libkorder/dynamic_dll.hh
index 7e84042fdab924dcb34d127301f4cea9276a1302..3aea043c6be822b29f6163ba3369a514c9faf41d 100644
--- a/mex/sources/libkorder/dynamic_dll.hh
+++ b/mex/sources/libkorder/dynamic_dll.hh
@@ -29,17 +29,23 @@
 # include <dlfcn.h> // unix/linux DLL (.so) handling routines
 #endif
 
-#include <string>
 #include <memory>
+#include <string>
 #include <utility>
 
 #include "dynare_exception.hh"
 
 #include "dynamic_abstract_class.hh"
 
-using dynamic_tt_fct = void (*)(const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, double *T);
-using dynamic_resid_or_g1_fct = void (*)(const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, const double *T, double *resid_or_g1);
-using dynamic_higher_deriv_fct = void (*)(const double *y, const double *x, int nb_row_x, const double *params, const double *steady_state, int it_, const double *T, double *g_i, double *g_j, double *g_v);
+using dynamic_tt_fct
+    = void (*)(const double* y, const double* x, int nb_row_x, const double* params,
+               const double* steady_state, int it_, double* T);
+using dynamic_resid_or_g1_fct
+    = void (*)(const double* y, const double* x, int nb_row_x, const double* params,
+               const double* steady_state, int it_, const double* T, double* resid_or_g1);
+using dynamic_higher_deriv_fct = void (*)(const double* y, const double* x, int nb_row_x,
+                                          const double* params, const double* steady_state, int it_,
+                                          const double* T, double* g_i, double* g_j, double* g_v);
 
 /**
  * creates pointer to Dynamic function inside <model>_dynamic.dll
@@ -54,13 +60,13 @@ private:
 #if defined(_WIN32) || defined(__CYGWIN32__)
   HINSTANCE dynamicHinstance; // DLL instance pointer in Windows
 #else
-  void *dynamicHinstance; // and in Linux or Mac
+  void* dynamicHinstance; // and in Linux or Mac
 #endif
   std::unique_ptr<double[]> tt; // Vector of temporary terms
 
   template<typename T>
   std::pair<T, dynamic_tt_fct>
-  getSymbolsFromDLL(const std::string &funcname, const std::string &fName)
+  getSymbolsFromDLL(const std::string& funcname, const std::string& fName)
   {
     dynamic_tt_fct tt;
     T deriv;
@@ -68,33 +74,36 @@ private:
 # pragma GCC diagnostic push
 # pragma GCC diagnostic ignored "-Wcast-function-type"
     deriv = reinterpret_cast<T>(GetProcAddress(dynamicHinstance, funcname.c_str()));
-    tt = reinterpret_cast<dynamic_tt_fct>(GetProcAddress(dynamicHinstance, (funcname + "_tt").c_str()));
+    tt = reinterpret_cast<dynamic_tt_fct>(
+        GetProcAddress(dynamicHinstance, (funcname + "_tt").c_str()));
 # pragma GCC diagnostic pop
 #else
-      deriv = reinterpret_cast<T>(dlsym(dynamicHinstance, funcname.c_str()));
-      tt = reinterpret_cast<dynamic_tt_fct>(dlsym(dynamicHinstance, (funcname + "_tt").c_str()));
+    deriv = reinterpret_cast<T>(dlsym(dynamicHinstance, funcname.c_str()));
+    tt = reinterpret_cast<dynamic_tt_fct>(dlsym(dynamicHinstance, (funcname + "_tt").c_str()));
 #endif
-      if (!deriv || !tt)
-        {
+    if (!deriv || !tt)
+      {
 #if defined(__CYGWIN32__) || defined(_WIN32)
-          FreeLibrary(dynamicHinstance);
+        FreeLibrary(dynamicHinstance);
 #else
-          dlclose(dynamicHinstance);
+        dlclose(dynamicHinstance);
 #endif
-          throw DynareException(__FILE__, __LINE__, "Error when loading symbols from " + fName
+        throw DynareException(__FILE__, __LINE__,
+                              "Error when loading symbols from " + fName
 #if !defined(__CYGWIN32__) && !defined(_WIN32)
-                                + ": " + dlerror()
+                                  + ": " + dlerror()
 #endif
-                                );
-        }
-      return { deriv, tt };
+        );
+      }
+    return {deriv, tt};
   }
+
 public:
   // construct and load Dynamic model DLL
-  explicit DynamicModelDLL(const std::string &fname, int ntt_arg, int order);
+  explicit DynamicModelDLL(const std::string& fname, int ntt_arg, int order);
   virtual ~DynamicModelDLL();
 
-  void eval(const Vector &y, const Vector &x, const Vector &params, const Vector &ySteady,
-            Vector &residual, std::vector<TwoDMatrix> &md) override;
+  void eval(const Vector& y, const Vector& x, const Vector& params, const Vector& ySteady,
+            Vector& residual, std::vector<TwoDMatrix>& md) override;
 };
 #endif
diff --git a/mex/sources/libkorder/dynamic_m.cc b/mex/sources/libkorder/dynamic_m.cc
index 85b9dd119bb89cbe9b9e838341de25732eb8c314..085c2b8ea066786dc7c50ed880c482f4f21dc83c 100644
--- a/mex/sources/libkorder/dynamic_m.cc
+++ b/mex/sources/libkorder/dynamic_m.cc
@@ -25,26 +25,25 @@
 
 #include "dynamic_m.hh"
 
-DynamicModelMFile::DynamicModelMFile(const std::string &modName, int ntt_arg) :
-  DynamicModelAC(ntt_arg),
-  DynamicMFilename{modName + ".dynamic"}
+DynamicModelMFile::DynamicModelMFile(const std::string& modName, int ntt_arg) :
+    DynamicModelAC(ntt_arg), DynamicMFilename {modName + ".dynamic"}
 {
 }
 
 /* NB: This is a duplicate of DynamicModelMatlabCaller::cmplxToReal() in
    perfect_foresight_problem MEX */
-mxArray *
-DynamicModelMFile::cmplxToReal(mxArray *cmplx_mx)
+mxArray*
+DynamicModelMFile::cmplxToReal(mxArray* cmplx_mx)
 {
-  mxArray *real_mx = mxCreateDoubleMatrix(mxGetM(cmplx_mx), mxGetN(cmplx_mx), mxREAL);
+  mxArray* real_mx = mxCreateDoubleMatrix(mxGetM(cmplx_mx), mxGetN(cmplx_mx), mxREAL);
 
 #if MX_HAS_INTERLEAVED_COMPLEX
-  mxComplexDouble *cmplx = mxGetComplexDoubles(cmplx_mx);
+  mxComplexDouble* cmplx = mxGetComplexDoubles(cmplx_mx);
 #else
-  double *cmplx_real = mxGetPr(cmplx_mx);
-  double *cmplx_imag = mxGetPi(cmplx_mx);
+  double* cmplx_real = mxGetPr(cmplx_mx);
+  double* cmplx_imag = mxGetPi(cmplx_mx);
 #endif
-  double *real = mxGetPr(real_mx);
+  double* real = mxGetPr(real_mx);
 
   for (size_t i = 0; i < mxGetNumberOfElements(cmplx_mx); i++)
 #if MX_HAS_INTERLEAVED_COMPLEX
@@ -62,11 +61,11 @@ DynamicModelMFile::cmplxToReal(mxArray *cmplx_mx)
 }
 
 void
-DynamicModelMFile::unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray *sparseMat, TwoDMatrix &tdm)
+DynamicModelMFile::unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray* sparseMat, TwoDMatrix& tdm)
 {
   int totalCols = mxGetN(sparseMat);
-  mwIndex *rowIdxVector = mxGetIr(sparseMat);
-  mwIndex *colIdxVector = mxGetJc(sparseMat);
+  mwIndex* rowIdxVector = mxGetIr(sparseMat);
+  mwIndex* colIdxVector = mxGetJc(sparseMat);
 
   assert(tdm.ncols() == 3);
   /* Under MATLAB, the following check always holds at equality; under Octave,
@@ -78,7 +77,7 @@ DynamicModelMFile::unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray *sparseMat,
   int output_row = 0;
 
   for (int i = 0; i < totalCols; i++)
-    for (int j = 0; j < static_cast<int>((colIdxVector[i+1]-colIdxVector[i])); j++, rind++)
+    for (int j = 0; j < static_cast<int>((colIdxVector[i + 1] - colIdxVector[i])); j++, rind++)
       {
         tdm.get(output_row, 0) = rowIdxVector[rind] + 1;
         tdm.get(output_row, 1) = i + 1;
@@ -114,32 +113,34 @@ DynamicModelMFile::unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray *sparseMat,
 }
 
 void
-DynamicModelMFile::eval(const Vector &y, const Vector &x, const Vector &modParams, const Vector &ySteady,
-                        Vector &residual, std::vector<TwoDMatrix> &md) noexcept(false)
+DynamicModelMFile::eval(const Vector& y, const Vector& x, const Vector& modParams,
+                        const Vector& ySteady, Vector& residual,
+                        std::vector<TwoDMatrix>& md) noexcept(false)
 {
-  mxArray *T_m = mxCreateDoubleMatrix(ntt, 1, mxREAL);
+  mxArray* T_m = mxCreateDoubleMatrix(ntt, 1, mxREAL);
 
-  mxArray *y_m = mxCreateDoubleMatrix(y.length(), 1, mxREAL);
+  mxArray* y_m = mxCreateDoubleMatrix(y.length(), 1, mxREAL);
   std::copy_n(y.base(), y.length(), mxGetPr(y_m));
 
-  mxArray *x_m = mxCreateDoubleMatrix(1, x.length(), mxREAL);
+  mxArray* x_m = mxCreateDoubleMatrix(1, x.length(), mxREAL);
   std::copy_n(x.base(), x.length(), mxGetPr(x_m));
 
-  mxArray *params_m = mxCreateDoubleMatrix(modParams.length(), 1, mxREAL);
+  mxArray* params_m = mxCreateDoubleMatrix(modParams.length(), 1, mxREAL);
   std::copy_n(modParams.base(), modParams.length(), mxGetPr(params_m));
 
-  mxArray *steady_state_m = mxCreateDoubleMatrix(ySteady.length(), 1, mxREAL);
+  mxArray* steady_state_m = mxCreateDoubleMatrix(ySteady.length(), 1, mxREAL);
   std::copy_n(ySteady.base(), ySteady.length(), mxGetPr(steady_state_m));
 
-  mxArray *it_m = mxCreateDoubleScalar(1.0);
-  mxArray *T_flag_m = mxCreateLogicalScalar(false);
+  mxArray* it_m = mxCreateDoubleScalar(1.0);
+  mxArray* T_flag_m = mxCreateLogicalScalar(false);
 
   {
     // Compute temporary terms (for all orders)
     std::string funcname = DynamicMFilename + "_g" + std::to_string(md.size()) + "_tt";
-    mxArray *plhs[1], *prhs[] = { T_m, y_m, x_m, params_m, steady_state_m, it_m };
+    mxArray *plhs[1], *prhs[] = {T_m, y_m, x_m, params_m, steady_state_m, it_m};
 
-    int retVal = mexCallMATLAB(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>, prhs, funcname.c_str());
+    int retVal = mexCallMATLAB(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>,
+                               prhs, funcname.c_str());
     if (retVal != 0)
       throw DynareException(__FILE__, __LINE__, "Trouble calling " + funcname);
 
@@ -150,19 +151,21 @@ DynamicModelMFile::eval(const Vector &y, const Vector &x, const Vector &modParam
   {
     // Compute residuals
     std::string funcname = DynamicMFilename + "_resid";
-    mxArray *plhs[1], *prhs[] = { T_m, y_m, x_m, params_m, steady_state_m, it_m, T_flag_m };
+    mxArray *plhs[1], *prhs[] = {T_m, y_m, x_m, params_m, steady_state_m, it_m, T_flag_m};
 
-    int retVal = mexCallMATLAB(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>, prhs, funcname.c_str());
+    int retVal = mexCallMATLAB(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>,
+                               prhs, funcname.c_str());
     if (retVal != 0)
       throw DynareException(__FILE__, __LINE__, "Trouble calling " + funcname);
 
     if (!mxIsDouble(plhs[0]) || mxIsSparse(plhs[0]))
-      throw DynareException(__FILE__, __LINE__, "Residual should be a dense array of double floats");
+      throw DynareException(__FILE__, __LINE__,
+                            "Residual should be a dense array of double floats");
 
     if (mxIsComplex(plhs[0]))
       plhs[0] = cmplxToReal(plhs[0]);
 
-    residual = Vector{plhs[0]};
+    residual = Vector {plhs[0]};
     mxDestroyArray(plhs[0]);
   }
 
@@ -170,28 +173,35 @@ DynamicModelMFile::eval(const Vector &y, const Vector &x, const Vector &modParam
     {
       // Compute model derivatives
       std::string funcname = DynamicMFilename + "_g" + std::to_string(i);
-      mxArray *plhs[1], *prhs[] = { T_m, y_m, x_m, params_m, steady_state_m, it_m, T_flag_m };
+      mxArray *plhs[1], *prhs[] = {T_m, y_m, x_m, params_m, steady_state_m, it_m, T_flag_m};
 
-      int retVal = mexCallMATLAB(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>, prhs, funcname.c_str());
+      int retVal = mexCallMATLAB(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>,
+                                 prhs, funcname.c_str());
       if (retVal != 0)
         throw DynareException(__FILE__, __LINE__, "Trouble calling " + funcname);
 
       if (!mxIsDouble(plhs[0]))
-        throw DynareException(__FILE__, __LINE__, "Derivatives matrix at order " + std::to_string(i) + "should be an array of double floats");
+        throw DynareException(__FILE__, __LINE__,
+                              "Derivatives matrix at order " + std::to_string(i)
+                                  + "should be an array of double floats");
 
       if (i == 1)
         {
           if (mxIsSparse(plhs[0]))
-            throw DynareException(__FILE__, __LINE__, "Derivatives matrix at order " + std::to_string(i) + " should be dense");
-          assert(static_cast<int>(mxGetM(plhs[0])) == md[i-1].nrows());
-          assert(static_cast<int>(mxGetN(plhs[0])) == md[i-1].ncols());
-          std::copy_n(mxGetPr(plhs[0]), mxGetM(plhs[0])*mxGetN(plhs[0]), md[i-1].base());
+            throw DynareException(__FILE__, __LINE__,
+                                  "Derivatives matrix at order " + std::to_string(i)
+                                      + " should be dense");
+          assert(static_cast<int>(mxGetM(plhs[0])) == md[i - 1].nrows());
+          assert(static_cast<int>(mxGetN(plhs[0])) == md[i - 1].ncols());
+          std::copy_n(mxGetPr(plhs[0]), mxGetM(plhs[0]) * mxGetN(plhs[0]), md[i - 1].base());
         }
       else
         {
           if (!mxIsSparse(plhs[0]))
-            throw DynareException(__FILE__, __LINE__, "Derivatives matrix at order " + std::to_string(i) + " should be sparse");
-          unpackSparseMatrixAndCopyIntoTwoDMatData(plhs[0], md[i-1]);
+            throw DynareException(__FILE__, __LINE__,
+                                  "Derivatives matrix at order " + std::to_string(i)
+                                      + " should be sparse");
+          unpackSparseMatrixAndCopyIntoTwoDMatData(plhs[0], md[i - 1]);
         }
 
       mxDestroyArray(plhs[0]);
diff --git a/mex/sources/libkorder/dynamic_m.hh b/mex/sources/libkorder/dynamic_m.hh
index baafc4652db60ca9d3410b11fc29bf714533ff77..7cd6af78efa330e8c806d3d9f52e24faf25e1f67 100644
--- a/mex/sources/libkorder/dynamic_m.hh
+++ b/mex/sources/libkorder/dynamic_m.hh
@@ -36,16 +36,17 @@ private:
   /* Unpack a sparse matrix (of double floats) into a TwoDMatrix object.
      Real elements of the original matrix are copied as-is to the new one.
      Complex elements are replaced by NaNs. */
-  static void unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray *sparseMat, TwoDMatrix &tdm);
+  static void unpackSparseMatrixAndCopyIntoTwoDMatData(mxArray* sparseMat, TwoDMatrix& tdm);
   /* Given a complex dense matrix (of double floats), returns a real dense matrix of same size.
      Real elements of the original matrix are copied as-is to the new one.
      Complex elements are replaced by NaNs.
      Destroys the original matrix. */
-  static mxArray *cmplxToReal(mxArray *m);
+  static mxArray* cmplxToReal(mxArray* m);
+
 public:
-  explicit DynamicModelMFile(const std::string &modName, int ntt_arg);
+  explicit DynamicModelMFile(const std::string& modName, int ntt_arg);
   virtual ~DynamicModelMFile() = default;
-  void eval(const Vector &y, const Vector &x, const Vector &params, const Vector &ySteady,
-            Vector &residual, std::vector<TwoDMatrix> &md) override;
+  void eval(const Vector& y, const Vector& x, const Vector& params, const Vector& ySteady,
+            Vector& residual, std::vector<TwoDMatrix>& md) override;
 };
 #endif
diff --git a/mex/sources/libkorder/k_ord_dynare.cc b/mex/sources/libkorder/k_ord_dynare.cc
index 1ffbb2f3f20548f6b540b67a034e15488c1df0c8..6d231442d503c6cfff31fe97f604aa8619acbde2 100644
--- a/mex/sources/libkorder/k_ord_dynare.cc
+++ b/mex/sources/libkorder/k_ord_dynare.cc
@@ -23,23 +23,21 @@
 #include "dynamic_abstract_class.hh"
 #include "dynare_exception.hh"
 
-#include <utility>
 #include <cassert>
+#include <utility>
 
-KordpDynare::KordpDynare(const std::vector<std::string> &endo,
-                         const std::vector<std::string> &exo, int nexog, int npar,
-                         Vector &ysteady, TwoDMatrix &vcov, Vector &inParams, int nstat,
-                         int npred, int nforw, int nboth, const ConstVector &nnzd,
-                         int nsteps, int norder,
-                         Journal &jr, std::unique_ptr<DynamicModelAC> dynamicModelFile_arg,
-                         const std::vector<int> &dr_order, const ConstTwoDMatrix &llincidence) :
-  nStat{nstat}, nBoth{nboth}, nPred{npred}, nForw{nforw}, nExog{nexog}, nPar{npar},
-  nYs{npred + nboth}, nYss{nboth + nforw}, nY{nstat + npred + nboth + nforw},
-  nJcols{nExog+nY+nYs+nYss}, NNZD{nnzd}, nSteps{nsteps},
-  nOrder{norder}, journal{jr}, ySteady{ysteady}, params{inParams}, vCov{vcov},
-  md{1}, dnl{endo}, denl{exo}, dsnl{*this, dnl, denl},
-  ll_Incidence{llincidence},
-  dynamicModelFile{std::move(dynamicModelFile_arg)}
+KordpDynare::KordpDynare(const std::vector<std::string>& endo, const std::vector<std::string>& exo,
+                         int nexog, int npar, Vector& ysteady, TwoDMatrix& vcov, Vector& inParams,
+                         int nstat, int npred, int nforw, int nboth, const ConstVector& nnzd,
+                         int nsteps, int norder, Journal& jr,
+                         std::unique_ptr<DynamicModelAC> dynamicModelFile_arg,
+                         const std::vector<int>& dr_order, const ConstTwoDMatrix& llincidence) :
+    nStat {nstat},
+    nBoth {nboth}, nPred {npred}, nForw {nforw}, nExog {nexog}, nPar {npar}, nYs {npred + nboth},
+    nYss {nboth + nforw}, nY {nstat + npred + nboth + nforw}, nJcols {nExog + nY + nYs + nYss},
+    NNZD {nnzd}, nSteps {nsteps}, nOrder {norder}, journal {jr}, ySteady {ysteady},
+    params {inParams}, vCov {vcov}, md {1}, dnl {endo}, denl {exo}, dsnl {*this, dnl, denl},
+    ll_Incidence {llincidence}, dynamicModelFile {std::move(dynamicModelFile_arg)}
 {
   computeJacobianPermutation(dr_order);
 }
@@ -52,20 +50,22 @@ KordpDynare::solveDeterministicSteady()
 }
 
 void
-KordpDynare::evaluateSystem(Vector &out, [[maybe_unused]] const ConstVector &yy,
-                            [[maybe_unused]] const Vector &xx)
+KordpDynare::evaluateSystem(Vector& out, [[maybe_unused]] const ConstVector& yy,
+                            [[maybe_unused]] const Vector& xx)
 {
-  // This method is only called when checking the residuals at steady state (Approximation::check), so return zero residuals
+  // This method is only called when checking the residuals at steady state (Approximation::check),
+  // so return zero residuals
   out.zeros();
 }
 
 void
-KordpDynare::evaluateSystem(Vector &out, [[maybe_unused]] const ConstVector &yym,
-                            [[maybe_unused]] const ConstVector &yy,
-                            [[maybe_unused]] const ConstVector &yyp,
-                            [[maybe_unused]] const Vector &xx)
+KordpDynare::evaluateSystem(Vector& out, [[maybe_unused]] const ConstVector& yym,
+                            [[maybe_unused]] const ConstVector& yy,
+                            [[maybe_unused]] const ConstVector& yyp,
+                            [[maybe_unused]] const Vector& xx)
 {
-  // This method is only called when checking the residuals at steady state (Approximation::check), so return zero residuals
+  // This method is only called when checking the residuals at steady state (Approximation::check),
+  // so return zero residuals
   out.zeros();
 }
 
@@ -82,7 +82,7 @@ KordpDynare::calcDerivativesAtSteady()
   for (int i = 2; i <= nOrder; i++)
     {
       // Higher order derivatives, as sparse (3-column) matrices
-      dyn_md.emplace_back(static_cast<int>(NNZD[i-1]), 3);
+      dyn_md.emplace_back(static_cast<int>(NNZD[i - 1]), 3);
       dyn_md.back().zeros();
     }
 
@@ -91,7 +91,7 @@ KordpDynare::calcDerivativesAtSteady()
 
   Vector out(nY);
   out.zeros();
-  Vector llxSteady(nJcols-nExog);
+  Vector llxSteady(nJcols - nExog);
   LLxSteady(ySteady, llxSteady);
 
   dynamicModelFile->eval(llxSteady, xx, params, ySteady, out, dyn_md);
@@ -101,9 +101,9 @@ KordpDynare::calcDerivativesAtSteady()
 }
 
 void
-KordpDynare::populateDerivativesContainer(const std::vector<TwoDMatrix> &dyn_md, int ord)
+KordpDynare::populateDerivativesContainer(const std::vector<TwoDMatrix>& dyn_md, int ord)
 {
-  const TwoDMatrix &g = dyn_md[ord-1];
+  const TwoDMatrix& g = dyn_md[ord - 1];
 
   // model derivatives FSSparseTensor instance
   auto mdTi = std::make_unique<FSSparseTensor>(ord, nJcols, nY);
@@ -124,8 +124,8 @@ KordpDynare::populateDerivativesContainer(const std::vector<TwoDMatrix> &dyn_md,
   else // ord ≥ 2
     for (int i = 0; i < g.nrows(); i++)
       {
-        int j = static_cast<int>(g.get(i, 0))-1;
-        int i1 = static_cast<int>(g.get(i, 1))-1;
+        int j = static_cast<int>(g.get(i, 0)) - 1;
+        int i1 = static_cast<int>(g.get(i, 1)) - 1;
         if (j < 0 || i1 < 0)
           continue; // Discard empty entries (see comment in DynamicModelAC::unpackSparseMatrix())
 
@@ -150,21 +150,21 @@ KordpDynare::populateDerivativesContainer(const std::vector<TwoDMatrix> &dyn_md,
 /* Returns ySteady extended with leads and lags suitable for passing to
    <model>_dynamic */
 void
-KordpDynare::LLxSteady(const Vector &yS, Vector &llxSteady)
+KordpDynare::LLxSteady(const Vector& yS, Vector& llxSteady)
 {
-  if (yS.length() == nJcols-nExog)
+  if (yS.length() == nJcols - nExog)
     throw DynareException(__FILE__, __LINE__, "ySteady already of right size");
 
   /* Create temporary square 2D matrix size nEndo×nEndo (sparse)
      for the lag, current and lead blocks of the jacobian */
-  if (llxSteady.length() != nJcols-nExog)
+  if (llxSteady.length() != nJcols - nExog)
     throw DynareException(__FILE__, __LINE__, "llxSteady has wrong size");
 
   for (int ll_row = 0; ll_row < ll_Incidence.nrows(); ll_row++)
     // populate (non-sparse) vector with ysteady values
     for (int i = 0; i < nY; i++)
       if (ll_Incidence.get(ll_row, i))
-        llxSteady[static_cast<int>(ll_Incidence.get(ll_row, i))-1] = yS[i];
+        llxSteady[static_cast<int>(ll_Incidence.get(ll_row, i)) - 1] = yS[i];
 }
 
 /*
@@ -186,33 +186,34 @@ KordpDynare::LLxSteady(const Vector &yS, Vector &llxSteady)
    dr_order is typically equal to oo_.dr.order_var.
 */
 void
-KordpDynare::computeJacobianPermutation(const std::vector<int> &dr_order)
+KordpDynare::computeJacobianPermutation(const std::vector<int>& dr_order)
 {
   // Compute restricted inverse DR-orderings: x⁻→y⁻ and x⁺→y⁺
-  std::vector<int> dr_inv_order_forw(nBoth+nForw), dr_inv_order_pred(nBoth+nPred);
+  std::vector<int> dr_inv_order_forw(nBoth + nForw), dr_inv_order_pred(nBoth + nPred);
   std::iota(dr_inv_order_forw.begin(), dr_inv_order_forw.end(), 0);
-  std::sort(dr_inv_order_forw.begin(), dr_inv_order_forw.end(),
-            [&](int i, int j) { return dr_order[nStat+nPred+i] < dr_order[nStat+nPred+j]; });
+  std::sort(dr_inv_order_forw.begin(), dr_inv_order_forw.end(), [&](int i, int j) {
+    return dr_order[nStat + nPred + i] < dr_order[nStat + nPred + j];
+  });
   std::iota(dr_inv_order_pred.begin(), dr_inv_order_pred.end(), 0);
   std::sort(dr_inv_order_pred.begin(), dr_inv_order_pred.end(),
-            [&](int i, int j) { return dr_order[nStat+i] < dr_order[nStat+j]; });
+            [&](int i, int j) { return dr_order[nStat + i] < dr_order[nStat + j]; });
 
   // Compute restricted DR-orderings: y⁻→x⁻ and y⁺→x⁺
-  std::vector<int> dr_order_forw(nBoth+nForw), dr_order_pred(nBoth+nPred);
-  for (int i = 0; i < nBoth+nForw; i++)
+  std::vector<int> dr_order_forw(nBoth + nForw), dr_order_pred(nBoth + nPred);
+  for (int i = 0; i < nBoth + nForw; i++)
     dr_order_forw[dr_inv_order_forw[i]] = i;
-  for (int i = 0; i < nBoth+nPred; i++)
+  for (int i = 0; i < nBoth + nPred; i++)
     dr_order_pred[dr_inv_order_pred[i]] = i;
 
   // Compute Dynare++ → Dynare ordering
   dynppToDyn.resize(nJcols);
   int j = 0;
   for (; j < nYss; j++)
-    dynppToDyn[j] = dr_order_forw[j]+nYs+nY; // Forward variables
-  for (; j < nYss+nY; j++)
-    dynppToDyn[j] = dr_order[j-nYss]+nYs; // Variables in current period
-  for (; j < nYss+nY+nYs; j++)
-    dynppToDyn[j] = dr_order_pred[j-nY-nYss]; // Predetermined variables
+    dynppToDyn[j] = dr_order_forw[j] + nYs + nY; // Forward variables
+  for (; j < nYss + nY; j++)
+    dynppToDyn[j] = dr_order[j - nYss] + nYs; // Variables in current period
+  for (; j < nYss + nY + nYs; j++)
+    dynppToDyn[j] = dr_order_pred[j - nY - nYss]; // Predetermined variables
   for (; j < nJcols; j++)
     dynppToDyn[j] = j; // Exogenous
 
@@ -222,16 +223,15 @@ KordpDynare::computeJacobianPermutation(const std::vector<int> &dr_order)
     dynToDynpp[dynppToDyn[i]] = i;
 }
 
-DynareNameList::DynareNameList(std::vector<std::string> names_arg)
-  : names(std::move(names_arg))
+DynareNameList::DynareNameList(std::vector<std::string> names_arg) : names(std::move(names_arg))
 {
 }
 
-DynareStateNameList::DynareStateNameList(const KordpDynare &dynare, const DynareNameList &dnl,
-                                         const DynareNameList &denl)
+DynareStateNameList::DynareStateNameList(const KordpDynare& dynare, const DynareNameList& dnl,
+                                         const DynareNameList& denl)
 {
   for (int i = 0; i < dynare.nYs; i++)
-    names.emplace_back(dnl.getName(i+dynare.nstat()));
+    names.emplace_back(dnl.getName(i + dynare.nstat()));
   for (int i = 0; i < dynare.nexog(); i++)
     names.emplace_back(denl.getName(i));
 }
diff --git a/mex/sources/libkorder/k_ord_dynare.hh b/mex/sources/libkorder/k_ord_dynare.hh
index 9cccbef7ff3afcb6440e439aa2473602ee59abf8..a9592c0f471a6f4f77994de423374b986fcc10b9 100644
--- a/mex/sources/libkorder/k_ord_dynare.hh
+++ b/mex/sources/libkorder/k_ord_dynare.hh
@@ -20,18 +20,18 @@
 #ifndef K_ORD_DYNARE3_H
 #define K_ORD_DYNARE3_H
 
-#include <vector>
-#include <string>
 #include <memory>
+#include <string>
+#include <vector>
 
-#include "journal.hh"
 #include "Vector.hh"
-#include "twod_matrix.hh"
-#include "t_container.hh"
-#include "sparse_tensor.hh"
 #include "decision_rule.hh"
-#include "dynamic_model.hh"
 #include "dynamic_abstract_class.hh"
+#include "dynamic_model.hh"
+#include "journal.hh"
+#include "sparse_tensor.hh"
+#include "t_container.hh"
+#include "twod_matrix.hh"
 
 class KordpDynare;
 
@@ -39,6 +39,7 @@ class KordpDynare;
 class DynareNameList : public NameList
 {
   std::vector<std::string> names;
+
 public:
   DynareNameList(std::vector<std::string> names_arg);
   int
@@ -46,7 +47,7 @@ public:
   {
     return static_cast<int>(names.size());
   }
-  const std::string &
+  const std::string&
   getName(int i) const override
   {
     return names[i];
@@ -56,15 +57,16 @@ public:
 class DynareStateNameList : public NameList
 {
   std::vector<std::string> names;
+
 public:
-  DynareStateNameList(const KordpDynare &dynare, const DynareNameList &dnl,
-                      const DynareNameList &denl);
+  DynareStateNameList(const KordpDynare& dynare, const DynareNameList& dnl,
+                      const DynareNameList& denl);
   int
   getNum() const override
   {
     return static_cast<int>(names.size());
   }
-  const std::string &
+  const std::string&
   getName(int i) const override
   {
     return names[i];
@@ -82,35 +84,35 @@ public:
   const int nForw;
   const int nExog;
   const int nPar;
-  const int nYs;      // = npred + nboth
-  const int nYss;     // = nboth + nforw
-  const int nY;       // = nstat + npred + nboth + nforw
-  const int nJcols;   // nb of jacobian columns = nExog+nY+nYs+nYss
-  const ConstVector &NNZD; /* the total number of non-zero derivative elements
+  const int nYs;           // = npred + nboth
+  const int nYss;          // = nboth + nforw
+  const int nY;            // = nstat + npred + nboth + nforw
+  const int nJcols;        // nb of jacobian columns = nExog+nY+nYs+nYss
+  const ConstVector& NNZD; /* the total number of non-zero derivative elements
                               where hessian is 2nd : NNZD(order=2) */
   const int nSteps;
   const int nOrder;
+
 private:
-  Journal &journal;
-  Vector &ySteady;
-  Vector &params;
-  TwoDMatrix &vCov;
+  Journal& journal;
+  Vector& ySteady;
+  Vector& params;
+  TwoDMatrix& vCov;
   TensorContainer<FSSparseTensor> md; // Model derivatives, in Dynare++ form
   DynareNameList dnl, denl;
   DynareStateNameList dsnl;
-  const ConstTwoDMatrix &ll_Incidence;
+  const ConstTwoDMatrix& ll_Incidence;
   std::vector<int> dynppToDyn; // Maps Dynare++ jacobian variable indices to Dynare ones
   std::vector<int> dynToDynpp; // Maps Dynare jacobian variable indices to Dynare++ ones
 
   std::unique_ptr<DynamicModelAC> dynamicModelFile;
+
 public:
-  KordpDynare(const std::vector<std::string> &endo,
-              const std::vector<std::string> &exo, int num_exo, int num_par,
-              Vector &ySteady, TwoDMatrix &vCov, Vector &params, int nstat, int nPred,
-              int nforw, int nboth, const ConstVector &NNZD,
-              int nSteps, int ord,
-              Journal &jr, std::unique_ptr<DynamicModelAC> dynamicModelFile_arg,
-              const std::vector<int> &varOrder, const ConstTwoDMatrix &ll_Incidence);
+  KordpDynare(const std::vector<std::string>& endo, const std::vector<std::string>& exo,
+              int num_exo, int num_par, Vector& ySteady, TwoDMatrix& vCov, Vector& params,
+              int nstat, int nPred, int nforw, int nboth, const ConstVector& NNZD, int nSteps,
+              int ord, Journal& jr, std::unique_ptr<DynamicModelAC> dynamicModelFile_arg,
+              const std::vector<int>& varOrder, const ConstTwoDMatrix& ll_Incidence);
 
   int
   nstat() const override
@@ -140,69 +142,69 @@ public:
   int
   ny() const
   {
-    return nStat+nBoth+nPred+nForw;
+    return nStat + nBoth + nPred + nForw;
   }
   int
   nys() const
   {
-    return nBoth+nPred;
+    return nBoth + nPred;
   }
   int
   order() const override
   {
     return nOrder;
   }
-  const std::vector<int> &
+  const std::vector<int>&
   getDynppToDyn() const
   {
     return dynppToDyn;
   }
-  const std::vector<int> &
+  const std::vector<int>&
   getDynToDynpp() const
   {
     return dynToDynpp;
   }
-  const NameList &
+  const NameList&
   getAllEndoNames() const override
   {
     return dnl;
   }
-  const NameList &
+  const NameList&
   getStateNames() const override
   {
     return dsnl;
   }
-  const NameList &
+  const NameList&
   getExogNames() const override
   {
     return denl;
   }
-  const TwoDMatrix &
+  const TwoDMatrix&
   getVcov() const override
   {
     return vCov;
   }
 
-  const TensorContainer<FSSparseTensor> &
+  const TensorContainer<FSSparseTensor>&
   getModelDerivatives() const override
   {
     return md;
   }
-  const Vector &
+  const Vector&
   getSteady() const override
   {
     return ySteady;
   }
-  Vector &
+  Vector&
   getSteady() override
   {
     return ySteady;
   }
 
   void solveDeterministicSteady() override;
-  void evaluateSystem(Vector &out, const ConstVector &yy, const Vector &xx) override;
-  void evaluateSystem(Vector &out, const ConstVector &yym, const ConstVector &yy,
-                      const ConstVector &yyp, const Vector &xx) override;
+  void evaluateSystem(Vector& out, const ConstVector& yy, const Vector& xx) override;
+  void evaluateSystem(Vector& out, const ConstVector& yym, const ConstVector& yy,
+                      const ConstVector& yyp, const Vector& xx) override;
   void calcDerivativesAtSteady() override;
   std::unique_ptr<DynamicModel>
   clone() const override
@@ -210,14 +212,16 @@ public:
     std::cerr << "KordpDynare::clone() not implemented" << std::endl;
     exit(EXIT_FAILURE);
   }
+
 private:
-  // Given the steady state in yS, returns in llxSteady the steady state extended with leads and lags
-  void LLxSteady(const Vector &yS, Vector &llxSteady);
+  // Given the steady state in yS, returns in llxSteady the steady state extended with leads and
+  // lags
+  void LLxSteady(const Vector& yS, Vector& llxSteady);
   /* Computes the permutations mapping back and forth between Dynare and
      Dynare++ orderings of variables */
-  void computeJacobianPermutation(const std::vector<int> &var_order);
+  void computeJacobianPermutation(const std::vector<int>& var_order);
   // Fills model derivatives in Dynare++ form (at a given order) given the Dynare form
-  void populateDerivativesContainer(const std::vector<TwoDMatrix> &dyn_md, int ord);
+  void populateDerivativesContainer(const std::vector<TwoDMatrix>& dyn_md, int ord);
 };
 
 #endif
diff --git a/mex/sources/libkorder/kord/approximation.cc b/mex/sources/libkorder/kord/approximation.cc
index ffb4abfe73923e4dbfc948a08fc6efcf0cba5d94..e375c513211ecf49d16811a7e9d3596350b21cb1 100644
--- a/mex/sources/libkorder/kord/approximation.cc
+++ b/mex/sources/libkorder/kord/approximation.cc
@@ -20,15 +20,15 @@
 
 #include <utility>
 
-#include "kord_exception.hh"
 #include "approximation.hh"
 #include "first_order.hh"
+#include "kord_exception.hh"
 #include "korder_stoch.hh"
 
-ZAuxContainer::ZAuxContainer(const _Ctype *gss, int ngss, int ng, int ny, int nu)
-  : StackContainer<FGSTensor>(4, 1)
+ZAuxContainer::ZAuxContainer(const _Ctype* gss, int ngss, int ng, int ny, int nu) :
+    StackContainer<FGSTensor>(4, 1)
 {
-  stack_sizes = { ngss, ng, ny, nu };
+  stack_sizes = {ngss, ng, ny, nu};
   conts[0] = gss;
   calculateOffsets();
 }
@@ -37,7 +37,7 @@ ZAuxContainer::ZAuxContainer(const _Ctype *gss, int ngss, int ng, int ny, int nu
    argument we return ‘matrix’, for other three we return ‘zero’. */
 
 ZAuxContainer::itype
-ZAuxContainer::getType(int i, const Symmetry &s) const
+ZAuxContainer::getType(int i, const Symmetry& s) const
 {
   if (i == 0)
     {
@@ -49,20 +49,20 @@ ZAuxContainer::getType(int i, const Symmetry &s) const
   return itype::zero;
 }
 
-Approximation::Approximation(DynamicModel &m, Journal &j, int ns, bool dr_centr, bool pruned_dr, double qz_crit)
-  : model(m), journal(j),
-    ypart(model.nstat(), model.npred(), model.nboth(), model.nforw()),
-    mom(UNormalMoments(model.order(), model.getVcov())),
-    nvs{ypart.nys(), model.nexog(), model.nexog(), 1},
-    steps(ns),
-    dr_centralize(dr_centr), pruning(pruned_dr),
-    qz_criterium(qz_crit), ss(ypart.ny(), steps+1)
+Approximation::Approximation(DynamicModel& m, Journal& j, int ns, bool dr_centr, bool pruned_dr,
+                             double qz_crit) :
+    model(m),
+    journal(j), ypart(model.nstat(), model.npred(), model.nboth(), model.nforw()),
+    mom(UNormalMoments(model.order(), model.getVcov())), nvs {ypart.nys(), model.nexog(),
+                                                              model.nexog(), 1},
+    steps(ns), dr_centralize(dr_centr), pruning(pruned_dr), qz_criterium(qz_crit),
+    ss(ypart.ny(), steps + 1)
 {
   ss.nans();
 }
 
 /* This just returns ‘fdr’ with a check that it is created. */
-const FoldDecisionRule &
+const FoldDecisionRule&
 Approximation::getFoldDecisionRule() const
 {
   KORD_RAISE_IF(!fdr,
@@ -71,21 +71,21 @@ Approximation::getFoldDecisionRule() const
 }
 
 /* This just returns ‘fdr_pruning’ with a check that it is created. */
-const UnfoldDecisionRule &
+const UnfoldDecisionRule&
 Approximation::getUnfoldDecisionRulePruning() const
 {
-  KORD_RAISE_IF(!udr_pruning,
-                "Unfolded decision rule has not been created in Approximation::getUnfoldDecisionRule");
+  KORD_RAISE_IF(
+      !udr_pruning,
+      "Unfolded decision rule has not been created in Approximation::getUnfoldDecisionRule");
   return *udr_pruning;
 }
 
-
 /* This just returns ‘udr’ with a check that it is created. */
-const UnfoldDecisionRule &
+const UnfoldDecisionRule&
 Approximation::getUnfoldDecisionRule() const
 {
-  KORD_RAISE_IF(!udr,
-                "Unfolded decision rule has not been created in Approximation::getUnfoldDecisionRule");
+  KORD_RAISE_IF(
+      !udr, "Unfolded decision rule has not been created in Approximation::getUnfoldDecisionRule");
   return *udr;
 }
 
@@ -97,15 +97,13 @@ void
 Approximation::approxAtSteady()
 {
   model.calcDerivativesAtSteady();
-  FirstOrder fo(model.nstat(), model.npred(), model.nboth(), model.nforw(),
-                model.nexog(), model.getModelDerivatives().get(Symmetry{1}),
-                journal, qz_criterium);
+  FirstOrder fo(model.nstat(), model.npred(), model.nboth(), model.nforw(), model.nexog(),
+                model.getModelDerivatives().get(Symmetry {1}), journal, qz_criterium);
 
   if (model.order() >= 2)
     {
       KOrder korder(model.nstat(), model.npred(), model.nboth(), model.nforw(),
-                    model.getModelDerivatives(), fo.getGy(), fo.getGu(),
-                    model.getVcov(), journal);
+                    model.getModelDerivatives(), fo.getGy(), fo.getGu(), model.getVcov(), journal);
       korder.switchToFolded();
       for (int k = 2; k <= model.order(); k++)
         korder.performStep<Storage::fold>(k);
@@ -157,17 +155,17 @@ Approximation::walkStochSteady()
      to ‘ss’. */
   model.solveDeterministicSteady();
   approxAtSteady();
-  Vector steady0{ss.getCol(0)};
+  Vector steady0 {ss.getCol(0)};
   steady0 = model.getSteady();
 
   double sigma_so_far = 0.0;
-  double dsigma = (steps == 0) ? 0.0 : 1.0/steps;
+  double dsigma = (steps == 0) ? 0.0 : 1.0 / steps;
   for (int i = 1; i <= steps; i++)
     {
       JournalRecordPair pa(journal);
-      pa << "Approximation about stochastic steady for sigma=" << sigma_so_far+dsigma << endrec;
+      pa << "Approximation about stochastic steady for sigma=" << sigma_so_far + dsigma << endrec;
 
-      Vector last_steady(const_cast<const Vector &>(model.getSteady()));
+      Vector last_steady(const_cast<const Vector&>(model.getSteady()));
 
       // calculate fix-point of the last rule for ‘dsigma’
       /* We form the DRFixPoint object from the last rule with σ=dsigma. Then
@@ -176,8 +174,9 @@ Approximation::walkStochSteady()
       DRFixPoint<Storage::fold> fp(*rule_ders, ypart, model.getSteady(), dsigma);
       bool converged = fp.calcFixPoint(model.getSteady());
       JournalRecord rec(journal);
-      rec << "Fix point calcs: iter=" << fp.getNumIter() << ", newton_iter="
-          << fp.getNewtonTotalIter() << ", last_newton_iter=" << fp.getNewtonLastIter() << ".";
+      rec << "Fix point calcs: iter=" << fp.getNumIter()
+          << ", newton_iter=" << fp.getNewtonTotalIter()
+          << ", last_newton_iter=" << fp.getNewtonLastIter() << ".";
       if (converged)
         rec << " Converged." << endrec;
       else
@@ -185,7 +184,7 @@ Approximation::walkStochSteady()
           rec << " Not converged!!" << endrec;
           KORD_RAISE_X("Fix point calculation not converged", KORD_FP_NOT_CONV);
         }
-      Vector steadyi{ss.getCol(i)};
+      Vector steadyi {ss.getCol(i)};
       steadyi = model.getSteady();
 
       // calculate ‘hh’ as expectations of the last g**
@@ -193,11 +192,11 @@ Approximation::walkStochSteady()
          minus the old steady state. Then we create StochForwardDerivs object,
          which calculates the derivatives of g** expectations at new sigma and
          new steady. */
-      Vector dy(const_cast<const Vector &>(model.getSteady()));
+      Vector dy(const_cast<const Vector&>(model.getSteady()));
       dy.add(-1.0, last_steady);
 
-      StochForwardDerivs<Storage::fold> hh(ypart, model.nexog(), *rule_ders_ss, mom, dy,
-                                           dsigma, sigma_so_far);
+      StochForwardDerivs<Storage::fold> hh(ypart, model.nexog(), *rule_ders_ss, mom, dy, dsigma,
+                                           sigma_so_far);
       JournalRecord rec1(journal);
       rec1 << "Calculation of g** expectations done" << endrec;
 
@@ -205,38 +204,35 @@ Approximation::walkStochSteady()
       /* We calculate derivatives of the model at the new steady, form
          KOrderStoch object and solve, and save the rule. */
       model.calcDerivativesAtSteady();
-      KOrderStoch korder_stoch(ypart, model.nexog(), model.getModelDerivatives(),
-                               hh, journal);
+      KOrderStoch korder_stoch(ypart, model.nexog(), model.getModelDerivatives(), hh, journal);
       for (int d = 1; d <= model.order(); d++)
         korder_stoch.performStep<Storage::fold>(d);
 
       saveRuleDerivs(korder_stoch.getFoldDers());
 
-      check(sigma_so_far+dsigma);
+      check(sigma_so_far + dsigma);
       sigma_so_far += dsigma;
     }
 
   // construct the resulting decision rules
   udr.reset();
-  fdr = std::make_unique<FoldDecisionRule>(*rule_ders, ypart, model.nexog(),
-                                           model.getSteady(), 1.0-sigma_so_far);
+  fdr = std::make_unique<FoldDecisionRule>(*rule_ders, ypart, model.nexog(), model.getSteady(),
+                                           1.0 - sigma_so_far);
   if (pruning)
     {
-      fdr_pruning = std::make_unique<FoldDecisionRule>(*rule_ders, ypart, 
-                                                     model.nexog(), 
-                                                     model.getSteady(), 
-                                                     1.0-sigma_so_far,
-                                                     pruning);
+      fdr_pruning = std::make_unique<FoldDecisionRule>(
+          *rule_ders, ypart, model.nexog(), model.getSteady(), 1.0 - sigma_so_far, pruning);
       udr_pruning = std::make_unique<UnfoldDecisionRule>(*fdr_pruning);
-    } 
+    }
   if (steps == 0 && dr_centralize)
     {
       // centralize decision rule for zero steps
       DRFixPoint<Storage::fold> fp(*rule_ders, ypart, model.getSteady(), 1.0);
       bool converged = fp.calcFixPoint(model.getSteady());
       JournalRecord rec(journal);
-      rec << "Fix point calcs: iter=" << fp.getNumIter() << ", newton_iter="
-          << fp.getNewtonTotalIter() << ", last_newton_iter=" << fp.getNewtonLastIter() << ".";
+      rec << "Fix point calcs: iter=" << fp.getNumIter()
+          << ", newton_iter=" << fp.getNewtonTotalIter()
+          << ", last_newton_iter=" << fp.getNewtonLastIter() << ".";
       if (converged)
         rec << " Converged." << endrec;
       else
@@ -259,16 +255,17 @@ Approximation::walkStochSteady()
    from a temporary object and will be destroyed. */
 
 void
-Approximation::saveRuleDerivs(const FGSContainer &g)
+Approximation::saveRuleDerivs(const FGSContainer& g)
 {
   rule_ders = std::make_unique<FGSContainer>(g);
   rule_ders_s = std::make_unique<FGSContainer>(4);
   rule_ders_ss = std::make_unique<FGSContainer>(4);
-  for (auto &run : *rule_ders)
+  for (auto& run : *rule_ders)
     {
       auto ten_s = std::make_unique<FGSTensor>(ypart.nstat, ypart.nys(), *(run.second));
       rule_ders_s->insert(std::move(ten_s));
-      auto ten_ss = std::make_unique<FGSTensor>(ypart.nstat+ypart.npred, ypart.nyss(), *(run.second));
+      auto ten_ss
+          = std::make_unique<FGSTensor>(ypart.nstat + ypart.npred, ypart.nyss(), *(run.second));
       rule_ders_ss->insert(std::move(ten_ss));
     }
 }
@@ -289,36 +286,36 @@ Approximation::saveRuleDerivs(const FGSContainer &g)
    add the σᵈ/d! multiple to the result. */
 
 void
-Approximation::calcStochShift(Vector &out, double at_sigma) const
+Approximation::calcStochShift(Vector& out, double at_sigma) const
 {
   KORD_RAISE_IF(out.length() != ypart.ny(),
                 "Wrong length of output vector for Approximation::calcStochShift");
   out.zeros();
 
-  ZAuxContainer zaux(rule_ders_ss.get(), ypart.nyss(), ypart.ny(),
-                     ypart.nys(), model.nexog());
+  ZAuxContainer zaux(rule_ders_ss.get(), ypart.nyss(), ypart.ny(), ypart.nys(), model.nexog());
 
   int dfac = 1;
   for (int d = 1; d <= rule_ders->getMaxDim(); d++, dfac *= d)
     if (KOrder::is_even(d))
       {
-        Symmetry sym{0, d, 0, 0};
+        Symmetry sym {0, d, 0, 0};
 
         // calculate F_u′ᵈ via ZAuxContainer
         auto ten = std::make_unique<FGSTensor>(ypart.ny(), TensorDimens(sym, nvs));
         ten->zeros();
         for (int l = 1; l <= d; l++)
           {
-            const FSSparseTensor &f = model.getModelDerivatives().get(Symmetry{l});
+            const FSSparseTensor& f = model.getModelDerivatives().get(Symmetry {l});
             zaux.multAndAdd(f, *ten);
           }
 
         // multiply with shocks and add to result
-        auto tmp = std::make_unique<FGSTensor>(ypart.ny(), TensorDimens(Symmetry{0, 0, 0, 0}, nvs));
+        auto tmp
+            = std::make_unique<FGSTensor>(ypart.ny(), TensorDimens(Symmetry {0, 0, 0, 0}, nvs));
         tmp->zeros();
-        ten->contractAndAdd(1, *tmp, mom.get(Symmetry{d}));
+        ten->contractAndAdd(1, *tmp, mom.get(Symmetry {d}));
 
-        out.add(pow(at_sigma, d)/dfac, tmp->getData());
+        out.add(pow(at_sigma, d) / dfac, tmp->getData());
       }
 }
 
@@ -343,8 +340,8 @@ Approximation::check(double at_sigma) const
   calcStochShift(stoch_shift, at_sigma);
   stoch_shift.add(1.0, system_resid);
   JournalRecord rec1(journal);
-  rec1 << "Error of current approximation for shocks at sigma " << at_sigma
-       << " is " << stoch_shift.getMax() << endrec;
+  rec1 << "Error of current approximation for shocks at sigma " << at_sigma << " is "
+       << stoch_shift.getMax() << endrec;
   calcStochShift(stoch_shift, 1.0);
   stoch_shift.add(1.0, system_resid);
   JournalRecord rec2(journal);
@@ -377,12 +374,12 @@ Approximation::check(double at_sigma) const
 TwoDMatrix
 Approximation::calcYCov() const
 {
-  const TwoDMatrix &gy = rule_ders->get(Symmetry{1, 0, 0, 0});
-  const TwoDMatrix &gu = rule_ders->get(Symmetry{0, 1, 0, 0});
+  const TwoDMatrix& gy = rule_ders->get(Symmetry {1, 0, 0, 0});
+  const TwoDMatrix& gu = rule_ders->get(Symmetry {0, 1, 0, 0});
   TwoDMatrix G(model.numeq(), model.numeq());
   G.zeros();
   G.place(gy, 0, model.nstat());
-  TwoDMatrix B(const_cast<const TwoDMatrix &>(G));
+  TwoDMatrix B(const_cast<const TwoDMatrix&>(G));
   B.mult(-1.0);
   TwoDMatrix C(transpose(G));
   TwoDMatrix A(model.numeq(), model.numeq());
@@ -392,8 +389,8 @@ Approximation::calcYCov() const
 
   TwoDMatrix X((gu * model.getVcov()) * transpose(gu));
 
-  GeneralSylvester gs(1, model.numeq(), model.numeq(), 0,
-                      A.getData(), B.getData(), C.getData(), X.getData());
+  GeneralSylvester gs(1, model.numeq(), model.numeq(), 0, A.getData(), B.getData(), C.getData(),
+                      X.getData());
   gs.solve();
 
   return X;
diff --git a/mex/sources/libkorder/kord/approximation.hh b/mex/sources/libkorder/kord/approximation.hh
index e2b2ae505bf73bb36f6f8d6ee99f69fe27b5ebab..1a3892ba22a4933129e3d08aaa2ca7e392704f84 100644
--- a/mex/sources/libkorder/kord/approximation.hh
+++ b/mex/sources/libkorder/kord/approximation.hh
@@ -64,10 +64,10 @@
 #ifndef APPROXIMATION_H
 #define APPROXIMATION_H
 
-#include "dynamic_model.hh"
 #include "decision_rule.hh"
-#include "korder.hh"
+#include "dynamic_model.hh"
 #include "journal.hh"
+#include "korder.hh"
 
 #include <memory>
 
@@ -87,8 +87,8 @@ class ZAuxContainer : public StackContainer<FGSTensor>, public FoldedStackContai
 public:
   using _Ctype = StackContainer<FGSTensor>::_Ctype;
   using itype = StackContainer<FGSTensor>::itype;
-  ZAuxContainer(const _Ctype *gss, int ngss, int ng, int ny, int nu);
-  itype getType(int i, const Symmetry &s) const override;
+  ZAuxContainer(const _Ctype* gss, int ngss, int ng, int ny, int nu);
+  itype getType(int i, const Symmetry& s) const override;
 };
 
 /* This class provides an interface to approximation algorithms. The core
@@ -119,8 +119,8 @@ public:
 
 class Approximation
 {
-  DynamicModel &model;
-  Journal &journal;
+  DynamicModel& model;
+  Journal& journal;
   std::unique_ptr<FGSContainer> rule_ders;
   std::unique_ptr<FGSContainer> rule_ders_s;
   std::unique_ptr<FGSContainer> rule_ders_ss;
@@ -136,18 +136,19 @@ class Approximation
   bool pruning;
   double qz_criterium;
   TwoDMatrix ss;
+
 public:
-  Approximation(DynamicModel &m, Journal &j, int ns, bool dr_centr, bool pruning, double qz_crit);
+  Approximation(DynamicModel& m, Journal& j, int ns, bool dr_centr, bool pruning, double qz_crit);
 
-  const FoldDecisionRule &getFoldDecisionRule() const;
-  const UnfoldDecisionRule &getUnfoldDecisionRulePruning() const;
-  const UnfoldDecisionRule &getUnfoldDecisionRule() const;
-  const TwoDMatrix &
+  const FoldDecisionRule& getFoldDecisionRule() const;
+  const UnfoldDecisionRule& getUnfoldDecisionRulePruning() const;
+  const UnfoldDecisionRule& getUnfoldDecisionRule() const;
+  const TwoDMatrix&
   getSS() const
   {
     return ss;
   }
-  const DynamicModel &
+  const DynamicModel&
   getModel() const
   {
     return model;
@@ -155,25 +156,26 @@ public:
 
   void walkStochSteady();
   TwoDMatrix calcYCov() const;
-  const FGSContainer &
+  const FGSContainer&
   get_rule_ders() const
   {
     return *rule_ders;
   }
-  const FGSContainer &
+  const FGSContainer&
   get_rule_ders_s() const
   {
     return *rule_ders_s;
   }
-  const FGSContainer &
+  const FGSContainer&
   get_rule_ders_ss() const
   {
     return *rule_ders_ss;
   }
+
 protected:
   void approxAtSteady();
-  void calcStochShift(Vector &out, double at_sigma) const;
-  void saveRuleDerivs(const FGSContainer &g);
+  void calcStochShift(Vector& out, double at_sigma) const;
+  void saveRuleDerivs(const FGSContainer& g);
   void check(double at_sigma) const;
 };
 
diff --git a/mex/sources/libkorder/kord/decision_rule.cc b/mex/sources/libkorder/kord/decision_rule.cc
index b433a72652960b20e77723a7e2b683e32a7ca53e..0bbc5dca6f0d0b8cd93eb11fd0fb14d9fcfba194 100644
--- a/mex/sources/libkorder/kord/decision_rule.cc
+++ b/mex/sources/libkorder/kord/decision_rule.cc
@@ -18,28 +18,28 @@
  * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#include "kord_exception.hh"
 #include "decision_rule.hh"
 #include "dynamic_model.hh"
+#include "kord_exception.hh"
 
 #include "SymSchurDecomp.hh"
 
 #include <memory>
 
 // FoldDecisionRule conversion from UnfoldDecisionRule
-FoldDecisionRule::FoldDecisionRule(const UnfoldDecisionRule &udr)
-  : DecisionRuleImpl<Storage::fold>(ctraits<Storage::fold>::Tpol(udr.nrows(), udr.nvars()),
+FoldDecisionRule::FoldDecisionRule(const UnfoldDecisionRule& udr) :
+    DecisionRuleImpl<Storage::fold>(ctraits<Storage::fold>::Tpol(udr.nrows(), udr.nvars()),
                                     udr.ypart, udr.nu, udr.ysteady)
 {
-  for (const auto &it : udr)
+  for (const auto& it : udr)
     insert(std::make_unique<ctraits<Storage::fold>::Ttensym>(*(it.second)));
 }
 
 // UnfoldDecisionRule conversion from FoldDecisionRule
-UnfoldDecisionRule::UnfoldDecisionRule(const FoldDecisionRule &fdr)
-  : DecisionRuleImpl<Storage::unfold>(ctraits<Storage::unfold>::Tpol(fdr.nrows(), fdr.nvars()),
+UnfoldDecisionRule::UnfoldDecisionRule(const FoldDecisionRule& fdr) :
+    DecisionRuleImpl<Storage::unfold>(ctraits<Storage::unfold>::Tpol(fdr.nrows(), fdr.nvars()),
                                       fdr.ypart, fdr.nu, fdr.ysteady)
 {
-  for (const auto &it : fdr)
+  for (const auto& it : fdr)
     insert(std::make_unique<ctraits<Storage::unfold>::Ttensym>(*(it.second)));
 }
diff --git a/mex/sources/libkorder/kord/decision_rule.hh b/mex/sources/libkorder/kord/decision_rule.hh
index 214c15d6c6a048f0972b7918b3cd035849770a27..80ce73016ac1a35a85afefeed6d73bef9ca0edc3 100644
--- a/mex/sources/libkorder/kord/decision_rule.hh
+++ b/mex/sources/libkorder/kord/decision_rule.hh
@@ -48,26 +48,30 @@
 class DecisionRule
 {
 public:
-  enum class emethod { horner, trad };
+  enum class emethod
+  {
+    horner,
+    trad
+  };
   virtual ~DecisionRule() = default;
 
   /* primitive evaluation (it takes a vector of state variables (predetermined,
      both and shocks) and returns the next period variables. Both input and
      output are in deviations from the rule's steady. */
-  virtual void eval(emethod em, Vector &out, const ConstVector &v) const = 0;
+  virtual void eval(emethod em, Vector& out, const ConstVector& v) const = 0;
 
   /* makes only one step of simulation (in terms of absolute values, not
      deviations) */
-  virtual void evaluate(emethod em, Vector &out, const ConstVector &ys,
-                        const ConstVector &u) const = 0;
+  virtual void evaluate(emethod em, Vector& out, const ConstVector& ys, const ConstVector& u) const
+      = 0;
 
   /* returns a new copy of the decision rule, which is centralized about
      provided fix-point */
-  virtual std::unique_ptr<DecisionRule> centralizedClone(const Vector &fixpoint) const = 0;
+  virtual std::unique_ptr<DecisionRule> centralizedClone(const Vector& fixpoint) const = 0;
 
-  virtual const Vector &getSteady() const = 0;
+  virtual const Vector& getSteady() const = 0;
   virtual int nexog() const = 0;
-  virtual const PartitionY &getYPart() const = 0;
+  virtual const PartitionY& getYPart() const = 0;
 };
 
 /* The main purpose of this class is to implement DecisionRule interface, which
@@ -111,27 +115,27 @@ protected:
   const Vector ysteady;
   const PartitionY ypart;
   const int nu;
+
 public:
-  DecisionRuleImpl(const _Tpol &pol, const PartitionY &yp, int nuu,
-                   const ConstVector &ys)
-    : ctraits<t>::Tpol(pol), ysteady(ys), ypart(yp), nu(nuu)
+  DecisionRuleImpl(const _Tpol& pol, const PartitionY& yp, int nuu, const ConstVector& ys) :
+      ctraits<t>::Tpol(pol), ysteady(ys), ypart(yp), nu(nuu)
   {
   }
-  DecisionRuleImpl(_Tpol &pol, const PartitionY &yp, int nuu,
-                   const ConstVector &ys)
-    : ctraits<t>::Tpol(0, yp.ny(), pol), ysteady(ys), ypart(yp),
-    nu(nuu)
+  DecisionRuleImpl(_Tpol& pol, const PartitionY& yp, int nuu, const ConstVector& ys) :
+      ctraits<t>::Tpol(0, yp.ny(), pol), ysteady(ys), ypart(yp), nu(nuu)
   {
   }
-  DecisionRuleImpl(const _Tg &g, const PartitionY &yp, int nuu,
-                   const ConstVector &ys, double sigma)
-    : ctraits<t>::Tpol(yp.ny(), yp.nys()+nuu), ysteady(ys), ypart(yp), nu(nuu)
+  DecisionRuleImpl(const _Tg& g, const PartitionY& yp, int nuu, const ConstVector& ys,
+                   double sigma) :
+      ctraits<t>::Tpol(yp.ny(), yp.nys() + nuu),
+      ysteady(ys), ypart(yp), nu(nuu)
   {
     fillTensors(g, sigma);
   }
-  DecisionRuleImpl(const _Tg &g, const PartitionY &yp, int nuu,
-                   const ConstVector &ys, double sigma, bool pruning)
-    : ctraits<t>::Tpol(yp.ny(), yp.nys()+nuu), ysteady(ys), ypart(yp), nu(nuu)
+  DecisionRuleImpl(const _Tg& g, const PartitionY& yp, int nuu, const ConstVector& ys, double sigma,
+                   bool pruning) :
+      ctraits<t>::Tpol(yp.ny(), yp.nys() + nuu),
+      ysteady(ys), ypart(yp), nu(nuu)
   {
     if (pruning)
       fillTensorsPruning(g);
@@ -139,44 +143,45 @@ public:
       fillTensors(g, sigma);
   }
 
-  DecisionRuleImpl(const _TW &W, int nys, int nuu,
-                   const ConstVector &ys)
-    : ctraits<t>::Tpol(1, nys+nuu), ysteady(ys), nu(nuu)
+  DecisionRuleImpl(const _TW& W, int nys, int nuu, const ConstVector& ys) :
+      ctraits<t>::Tpol(1, nys + nuu), ysteady(ys), nu(nuu)
   {
     fillTensors(W, nys);
   }
-  DecisionRuleImpl(const DecisionRuleImpl<t> &dr, const ConstVector &fixpoint)
-    : ctraits<t>::Tpol(dr.ypart.ny(), dr.ypart.nys()+dr.nu),
-    ysteady(fixpoint), ypart(dr.ypart), nu(dr.nu)
+  DecisionRuleImpl(const DecisionRuleImpl<t>& dr, const ConstVector& fixpoint) :
+      ctraits<t>::Tpol(dr.ypart.ny(), dr.ypart.nys() + dr.nu), ysteady(fixpoint), ypart(dr.ypart),
+      nu(dr.nu)
   {
     centralize(dr);
   }
-  const Vector &
+  const Vector&
   getSteady() const override
   {
     return ysteady;
   }
-  void evaluate(emethod em, Vector &out, const ConstVector &ys,
-                const ConstVector &u) const override;
-  std::unique_ptr<DecisionRule> centralizedClone(const Vector &fixpoint) const override;
+  void evaluate(emethod em, Vector& out, const ConstVector& ys,
+                const ConstVector& u) const override;
+  std::unique_ptr<DecisionRule> centralizedClone(const Vector& fixpoint) const override;
 
   int
   nexog() const override
   {
     return nu;
   }
-  const PartitionY &
+  const PartitionY&
   getYPart() const override
   {
     return ypart;
   }
+
 protected:
-  void fillTensors(const _Tg &g, double sigma);
-  void fillTensorsPruning(const _Tg &g);
-  void fillTensors(const _TW &W, int nys);
-  void centralize(const DecisionRuleImpl &dr);
+  void fillTensors(const _Tg& g, double sigma);
+  void fillTensorsPruning(const _Tg& g);
+  void fillTensors(const _TW& W, int nys);
+  void centralize(const DecisionRuleImpl& dr);
+
 public:
-  void eval(emethod em, Vector &out, const ConstVector &v) const override;
+  void eval(emethod em, Vector& out, const ConstVector& v) const override;
 };
 
 /* Here we have to fill the tensor polynomial. This involves two separated
@@ -190,14 +195,14 @@ public:
    The q-order approximation to the solution can be written as:
 
                   ⎡                                                               ⎤
-             q  1 ⎢       ⎛  l  ⎞⎡        ⎤            ᵢ ⎡          ⎤αₘ ⱼ ⎡  ⎤βₘ  ⎥ 
-    yₜ − ȳ = ∑  ──⎢   ∑   ⎢     ⎥⎢g_yⁱuʲσᵏ⎥            ∏ ⎢y*ₜ₋₁ − ȳ*⎥   ∏ ⎢uₜ⎥  σᵏ⎥ 
+             q  1 ⎢       ⎛  l  ⎞⎡        ⎤            ᵢ ⎡          ⎤αₘ ⱼ ⎡  ⎤βₘ  ⎥
+    yₜ − ȳ = ∑  ──⎢   ∑   ⎢     ⎥⎢g_yⁱuʲσᵏ⎥            ∏ ⎢y*ₜ₋₁ − ȳ*⎥   ∏ ⎢uₜ⎥  σᵏ⎥
             ˡ⁼¹ l!⎢ⁱ⁺ʲ⁺ᵏ⁼ˡ⎝i,j,k⎠⎣        ⎦α₁…αⱼβ₁…βⱼ ᵐ⁼¹⎣          ⎦  ᵐ⁼¹⎣  ⎦    ⎥
                   ⎣                                                               ⎦
 
                ⎡           ⎡                                   ⎤                           ⎤
-             q ⎢      ⎛i+j⎞⎢ₗ₋ᵢ₋ⱼ 1  ⎛l⎞ ⎡        ⎤            ⎥  ᵢ ⎡          ⎤αₘ ⱼ ⎡  ⎤βₘ⎥ 
-           = ∑ ⎢  ∑   ⎢   ⎥⎢  ∑   ── ⎢ ⎥ ⎢g_yⁱuʲσᵏ⎥          σᵏ⎥  ∏ ⎢y*ₜ₋₁ − ȳ*⎥   ∏ ⎢uₜ⎥  ⎥ 
+             q ⎢      ⎛i+j⎞⎢ₗ₋ᵢ₋ⱼ 1  ⎛l⎞ ⎡        ⎤            ⎥  ᵢ ⎡          ⎤αₘ ⱼ ⎡  ⎤βₘ⎥
+           = ∑ ⎢  ∑   ⎢   ⎥⎢  ∑   ── ⎢ ⎥ ⎢g_yⁱuʲσᵏ⎥          σᵏ⎥  ∏ ⎢y*ₜ₋₁ − ȳ*⎥   ∏ ⎢uₜ⎥  ⎥
             ˡ⁼¹⎢i+j≤l ⎝ i ⎠⎢ ᵏ⁼⁰  l! ⎝k⎠ ⎣        ⎦α₁…αⱼβ₁…βⱼ  ⎥ ᵐ⁼¹⎣          ⎦  ᵐ⁼¹⎣  ⎦  ⎥
                ⎣           ⎣                                   ⎦                           ⎦
 
@@ -217,13 +222,13 @@ public:
 
 template<Storage t>
 void
-DecisionRuleImpl<t>::fillTensors(const _Tg &g, double sigma)
+DecisionRuleImpl<t>::fillTensors(const _Tg& g, double sigma)
 {
-  IntSequence tns{ypart.nys(), nu};
+  IntSequence tns {ypart.nys(), nu};
   int dfact = 1;
   for (int d = 0; d <= g.getMaxDim(); d++, dfact *= d)
     {
-      auto g_yud = std::make_unique<_Ttensym>(ypart.ny(), ypart.nys()+nu, d);
+      auto g_yud = std::make_unique<_Ttensym>(ypart.ny(), ypart.nys() + nu, d);
       g_yud->zeros();
 
       // fill tensor of ‘g_yud’ of dimension ‘d’
@@ -239,16 +244,14 @@ DecisionRuleImpl<t>::fillTensors(const _Tg &g, double sigma)
 
       for (int i = 0; i <= d; i++)
         {
-          int j = d-i;
+          int j = d - i;
           int kfact = 1;
-          _Ttensor tmp(ypart.ny(),
-                       TensorDimens(Symmetry{i, j}, tns));
+          _Ttensor tmp(ypart.ny(), TensorDimens(Symmetry {i, j}, tns));
           tmp.zeros();
-          for (int k = 0; k+d <= g.getMaxDim(); k++, kfact *= k)
-            if (Symmetry sym{i, j, 0, k};
-                g.check(sym))
+          for (int k = 0; k + d <= g.getMaxDim(); k++, kfact *= k)
+            if (Symmetry sym {i, j, 0, k}; g.check(sym))
               {
-                double mult = pow(sigma, k)/dfact/kfact;
+                double mult = pow(sigma, k) / dfact / kfact;
                 tmp.add(mult, g.get(sym));
               }
           g_yud->addSubTensor(tmp);
@@ -260,31 +263,30 @@ DecisionRuleImpl<t>::fillTensors(const _Tg &g, double sigma)
 
 template<Storage t>
 void
-DecisionRuleImpl<t>::fillTensorsPruning(const _Tg &g)
+DecisionRuleImpl<t>::fillTensorsPruning(const _Tg& g)
 {
-  IntSequence tns{ypart.nys(), nu, 1};
+  IntSequence tns {ypart.nys(), nu, 1};
   int dfact = 1;
   for (int d = 0; d <= g.getMaxDim(); d++, dfact *= d)
     {
-      auto g_yusd = std::make_unique<_Ttensym>(ypart.ny(), ypart.nys()+nu+1, d);
+      auto g_yusd = std::make_unique<_Ttensym>(ypart.ny(), ypart.nys() + nu + 1, d);
       g_yusd->zeros();
       // fill tensor of ‘g_yusd’ of dimension ‘d’
-      /* 
+      /*
         Here we have to fill the tensor [g_(yuσ)ᵈ]. So we go through all pairs
         (i,j,k) such that i+j+k=d. We weight it with 1/(i+j+k)! The factorial
         is denoted dfact.
       */
       for (int i = 0; i <= d; i++)
         {
-          for (int j = 0; j <= d-i; j++)
+          for (int j = 0; j <= d - i; j++)
             {
-              int k = d-i-j;
-              _Ttensor tmp(ypart.ny(),
-                           TensorDimens(Symmetry{i, j, k}, tns));
+              int k = d - i - j;
+              _Ttensor tmp(ypart.ny(), TensorDimens(Symmetry {i, j, k}, tns));
               tmp.zeros();
-              if (Symmetry sym{i, j, 0, k}; g.check(sym))
+              if (Symmetry sym {i, j, 0, k}; g.check(sym))
                 {
-                  double mult = 1.0/dfact;
+                  double mult = 1.0 / dfact;
                   // mexPrintf("Symmetry found: %d %d %d %.2f %d\n", i, j, k, mult, kfact);
                   tmp.add(mult, g.get(sym));
                 }
@@ -297,13 +299,13 @@ DecisionRuleImpl<t>::fillTensorsPruning(const _Tg &g)
 
 template<Storage t>
 void
-DecisionRuleImpl<t>::fillTensors(const _TW &W, int nys)
+DecisionRuleImpl<t>::fillTensors(const _TW& W, int nys)
 {
-  IntSequence tns{nys, nu};
+  IntSequence tns {nys, nu};
   int dfact = 1;
   for (int d = 0; d <= W.getMaxDim(); d++, dfact *= d)
     {
-      auto W_yud = std::make_unique<_Ttensym>(1, nys+nu, d);
+      auto W_yud = std::make_unique<_Ttensym>(1, nys + nu, d);
       W_yud->zeros();
 
       // fill tensor of ‘g_yud’ of dimension ‘d’
@@ -319,15 +321,14 @@ DecisionRuleImpl<t>::fillTensors(const _TW &W, int nys)
 
       for (int i = 0; i <= d; i++)
         {
-          int j = d-i;
+          int j = d - i;
           int kfact = 1;
-          _Ttensor tmp(1, TensorDimens(Symmetry{i, j}, tns));
+          _Ttensor tmp(1, TensorDimens(Symmetry {i, j}, tns));
           tmp.zeros();
-          for (int k = 0; k+d <= W.getMaxDim(); k++, kfact *= k)
-            if (Symmetry sym{i, j, 0, k};
-                W.check(sym))
+          for (int k = 0; k + d <= W.getMaxDim(); k++, kfact *= k)
+            if (Symmetry sym {i, j, 0, k}; W.check(sym))
               {
-                double mult = 1.0/dfact/kfact;
+                double mult = 1.0 / dfact / kfact;
                 tmp.add(mult, W.get(sym));
               }
           W_yud->addSubTensor(tmp);
@@ -351,7 +352,7 @@ DecisionRuleImpl<t>::fillTensors(const _TW &W, int nys)
 
 template<Storage t>
 void
-DecisionRuleImpl<t>::centralize(const DecisionRuleImpl &dr)
+DecisionRuleImpl<t>::centralize(const DecisionRuleImpl& dr)
 {
   Vector dstate(ypart.nys() + nu);
   dstate.zeros();
@@ -365,9 +366,9 @@ DecisionRuleImpl<t>::centralize(const DecisionRuleImpl &dr)
   int dfac = 1;
   for (int d = 1; d <= dr.getMaxDim(); d++, dfac *= d)
     {
-      pol.derivative(d-1);
+      pol.derivative(d - 1);
       auto der = pol.evalPartially(d, dstate);
-      der->mult(1.0/dfac);
+      der->mult(1.0 / dfac);
       this->insert(std::move(der));
     }
 }
@@ -379,15 +380,15 @@ DecisionRuleImpl<t>::centralize(const DecisionRuleImpl &dr)
 
 template<Storage t>
 void
-DecisionRuleImpl<t>::evaluate(emethod em, Vector &out, const ConstVector &ys,
-                              const ConstVector &u) const
+DecisionRuleImpl<t>::evaluate(emethod em, Vector& out, const ConstVector& ys,
+                              const ConstVector& u) const
 {
   KORD_RAISE_IF(ys.length() != ypart.nys() || u.length() != nu,
                 "Wrong dimensions of input vectors in DecisionRuleImpl::evaluate");
   KORD_RAISE_IF(out.length() != ypart.ny(),
                 "Wrong dimension of output vector in DecisionRuleImpl::evaluate");
   ConstVector ysteady_pred(ysteady, ypart.nstat, ypart.nys());
-  Vector ys_u(ypart.nys()+nu);
+  Vector ys_u(ypart.nys() + nu);
   Vector ys_u1(ys_u, 0, ypart.nys());
   ys_u1 = ys;
   ys_u1.add(-1.0, ysteady_pred);
@@ -402,7 +403,7 @@ DecisionRuleImpl<t>::evaluate(emethod em, Vector &out, const ConstVector &ys,
 
 template<Storage t>
 std::unique_ptr<DecisionRule>
-DecisionRuleImpl<t>::centralizedClone(const Vector &fixpoint) const
+DecisionRuleImpl<t>::centralizedClone(const Vector& fixpoint) const
 {
   return std::make_unique<DecisionRuleImpl<t>>(*this, fixpoint);
 }
@@ -412,7 +413,7 @@ DecisionRuleImpl<t>::centralizedClone(const Vector &fixpoint) const
 
 template<Storage t>
 void
-DecisionRuleImpl<t>::eval(emethod em, Vector &out, const ConstVector &v) const
+DecisionRuleImpl<t>::eval(emethod em, Vector& out, const ConstVector& v) const
 {
   if (em == emethod::horner)
     _Tpol::evalHorner(out, v);
@@ -428,37 +429,37 @@ class UnfoldDecisionRule;
 class FoldDecisionRule : public DecisionRuleImpl<Storage::fold>
 {
   friend class UnfoldDecisionRule;
+
 public:
-  FoldDecisionRule(const ctraits<Storage::fold>::Tpol &pol, const PartitionY &yp, int nuu,
-                   const ConstVector &ys)
-    : DecisionRuleImpl<Storage::fold>(pol, yp, nuu, ys)
+  FoldDecisionRule(const ctraits<Storage::fold>::Tpol& pol, const PartitionY& yp, int nuu,
+                   const ConstVector& ys) :
+      DecisionRuleImpl<Storage::fold>(pol, yp, nuu, ys)
   {
   }
-  FoldDecisionRule(ctraits<Storage::fold>::Tpol &pol, const PartitionY &yp, int nuu,
-                   const ConstVector &ys)
-    : DecisionRuleImpl<Storage::fold>(pol, yp, nuu, ys)
+  FoldDecisionRule(ctraits<Storage::fold>::Tpol& pol, const PartitionY& yp, int nuu,
+                   const ConstVector& ys) :
+      DecisionRuleImpl<Storage::fold>(pol, yp, nuu, ys)
   {
   }
-  FoldDecisionRule(const ctraits<Storage::fold>::Tg &g, const PartitionY &yp, int nuu,
-                   const ConstVector &ys, double sigma)
-    : DecisionRuleImpl<Storage::fold>(g, yp, nuu, ys, sigma)
+  FoldDecisionRule(const ctraits<Storage::fold>::Tg& g, const PartitionY& yp, int nuu,
+                   const ConstVector& ys, double sigma) :
+      DecisionRuleImpl<Storage::fold>(g, yp, nuu, ys, sigma)
   {
   }
-  FoldDecisionRule(const ctraits<Storage::fold>::Tg &g, const PartitionY &yp, int nuu,
-                   const ConstVector &ys, double sigma, bool pruning)
-    : DecisionRuleImpl<Storage::fold>(g, yp, nuu, ys, sigma, pruning)
+  FoldDecisionRule(const ctraits<Storage::fold>::Tg& g, const PartitionY& yp, int nuu,
+                   const ConstVector& ys, double sigma, bool pruning) :
+      DecisionRuleImpl<Storage::fold>(g, yp, nuu, ys, sigma, pruning)
   {
   }
-  FoldDecisionRule(const ctraits<Storage::fold>::TW &W, int nys, int nuu,
-                   const ConstVector &ys)
-    : DecisionRuleImpl<Storage::fold>(W, nys, nuu, ys)
+  FoldDecisionRule(const ctraits<Storage::fold>::TW& W, int nys, int nuu, const ConstVector& ys) :
+      DecisionRuleImpl<Storage::fold>(W, nys, nuu, ys)
   {
   }
-  FoldDecisionRule(const DecisionRuleImpl<Storage::fold> &dr, const ConstVector &fixpoint)
-    : DecisionRuleImpl<Storage::fold>(dr, fixpoint)
+  FoldDecisionRule(const DecisionRuleImpl<Storage::fold>& dr, const ConstVector& fixpoint) :
+      DecisionRuleImpl<Storage::fold>(dr, fixpoint)
   {
   }
-  FoldDecisionRule(const UnfoldDecisionRule &udr);
+  FoldDecisionRule(const UnfoldDecisionRule& udr);
 };
 
 /* This is exactly the same as DecisionRuleImpl<Storage::unfold>, but with a
@@ -468,27 +469,28 @@ public:
 class UnfoldDecisionRule : public DecisionRuleImpl<Storage::unfold>
 {
   friend class FoldDecisionRule;
+
 public:
-  UnfoldDecisionRule(const ctraits<Storage::unfold>::Tpol &pol, const PartitionY &yp, int nuu,
-                     const ConstVector &ys)
-    : DecisionRuleImpl<Storage::unfold>(pol, yp, nuu, ys)
+  UnfoldDecisionRule(const ctraits<Storage::unfold>::Tpol& pol, const PartitionY& yp, int nuu,
+                     const ConstVector& ys) :
+      DecisionRuleImpl<Storage::unfold>(pol, yp, nuu, ys)
   {
   }
-  UnfoldDecisionRule(ctraits<Storage::unfold>::Tpol &pol, const PartitionY &yp, int nuu,
-                     const ConstVector &ys)
-    : DecisionRuleImpl<Storage::unfold>(pol, yp, nuu, ys)
+  UnfoldDecisionRule(ctraits<Storage::unfold>::Tpol& pol, const PartitionY& yp, int nuu,
+                     const ConstVector& ys) :
+      DecisionRuleImpl<Storage::unfold>(pol, yp, nuu, ys)
   {
   }
-  UnfoldDecisionRule(const ctraits<Storage::unfold>::Tg &g, const PartitionY &yp, int nuu,
-                     const ConstVector &ys, double sigma)
-    : DecisionRuleImpl<Storage::unfold>(g, yp, nuu, ys, sigma)
+  UnfoldDecisionRule(const ctraits<Storage::unfold>::Tg& g, const PartitionY& yp, int nuu,
+                     const ConstVector& ys, double sigma) :
+      DecisionRuleImpl<Storage::unfold>(g, yp, nuu, ys, sigma)
   {
   }
-  UnfoldDecisionRule(const DecisionRuleImpl<Storage::unfold> &dr, const ConstVector &fixpoint)
-    : DecisionRuleImpl<Storage::unfold>(dr, fixpoint)
+  UnfoldDecisionRule(const DecisionRuleImpl<Storage::unfold>& dr, const ConstVector& fixpoint) :
+      DecisionRuleImpl<Storage::unfold>(dr, fixpoint)
   {
   }
-  UnfoldDecisionRule(const FoldDecisionRule &udr);
+  UnfoldDecisionRule(const FoldDecisionRule& udr);
 };
 
 /* This class serves for calculation of the fix point of the decision rule
@@ -518,12 +520,12 @@ class DRFixPoint : public ctraits<t>::Tpol
   const PartitionY ypart;
   std::unique_ptr<_Tpol> bigf;
   std::unique_ptr<_Tpol> bigfder;
+
 public:
   using emethod = typename DecisionRule::emethod;
-  DRFixPoint(const _Tg &g, const PartitionY &yp,
-             const Vector &ys, double sigma);
+  DRFixPoint(const _Tg& g, const PartitionY& yp, const Vector& ys, double sigma);
 
-  bool calcFixPoint(Vector &out);
+  bool calcFixPoint(Vector& out);
 
   int
   getNumIter() const
@@ -540,9 +542,11 @@ public:
   {
     return newton_iter_total;
   }
+
 protected:
-  void fillTensors(const _Tg &g, double sigma);
-  bool solveNewton(Vector &y);
+  void fillTensors(const _Tg& g, double sigma);
+  bool solveNewton(Vector& y);
+
 private:
   int iter;
   int newton_iter_last;
@@ -555,15 +559,13 @@ private:
    calculated. */
 
 template<Storage t>
-DRFixPoint<t>::DRFixPoint(const _Tg &g, const PartitionY &yp,
-                          const Vector &ys, double sigma)
-  : ctraits<t>::Tpol(yp.ny(), yp.nys()),
-  ysteady(ys), ypart(yp)
+DRFixPoint<t>::DRFixPoint(const _Tg& g, const PartitionY& yp, const Vector& ys, double sigma) :
+    ctraits<t>::Tpol(yp.ny(), yp.nys()), ysteady(ys), ypart(yp)
 {
   fillTensors(g, sigma);
   _Tpol yspol(ypart.nstat, ypart.nys(), *this);
-  bigf = std::make_unique<_Tpol>(const_cast<const _Tpol &>(yspol));
-  _Ttensym &frst = bigf->get(Symmetry{1});
+  bigf = std::make_unique<_Tpol>(const_cast<const _Tpol&>(yspol));
+  _Ttensym& frst = bigf->get(Symmetry {1});
   for (int i = 0; i < ypart.nys(); i++)
     frst.get(i, i) = frst.get(i, i) - 1;
   bigfder = std::make_unique<_Tpol>(*bigf, 0);
@@ -576,7 +578,7 @@ DRFixPoint<t>::DRFixPoint(const _Tg &g, const PartitionY &yp,
 
 template<Storage t>
 void
-DRFixPoint<t>::fillTensors(const _Tg &g, double sigma)
+DRFixPoint<t>::fillTensors(const _Tg& g, double sigma)
 {
   int dfact = 1;
   for (int d = 0; d <= g.getMaxDim(); d++, dfact *= d)
@@ -584,11 +586,11 @@ DRFixPoint<t>::fillTensors(const _Tg &g, double sigma)
       auto g_yd = std::make_unique<_Ttensym>(ypart.ny(), ypart.nys(), d);
       g_yd->zeros();
       int kfact = 1;
-      for (int k = 0; d+k <= g.getMaxDim(); k++, kfact *= k)
-        if (g.check(Symmetry{d, 0, 0, k}))
+      for (int k = 0; d + k <= g.getMaxDim(); k++, kfact *= k)
+        if (g.check(Symmetry {d, 0, 0, k}))
           {
-            const _Ttensor &ten = g.get(Symmetry{d, 0, 0, k});
-            double mult = pow(sigma, k)/dfact/kfact;
+            const _Ttensor& ten = g.get(Symmetry {d, 0, 0, k});
+            double mult = pow(sigma, k) / dfact / kfact;
             g_yd->add(mult, ten);
           }
       this->insert(std::move(g_yd));
@@ -609,10 +611,10 @@ DRFixPoint<t>::fillTensors(const _Tg &g, double sigma)
 
 template<Storage t>
 bool
-DRFixPoint<t>::solveNewton(Vector &y)
+DRFixPoint<t>::solveNewton(Vector& y)
 {
   const double urelax_threshold = 1.e-5;
-  Vector sol(const_cast<const Vector &>(y));
+  Vector sol(const_cast<const Vector&>(y));
   Vector delta(y.length());
   newton_iter_last = 0;
   bool delta_finite = true;
@@ -642,7 +644,7 @@ DRFixPoint<t>::solveNewton(Vector &y)
           urelax = 1.0;
           while (!urelax_found && urelax > urelax_threshold)
             {
-              Vector soltmp(const_cast<const Vector &>(sol));
+              Vector soltmp(const_cast<const Vector&>(sol));
               soltmp.add(-urelax, delta);
               Vector f(sol.length());
               bigf->evalHorner(f, soltmp);
@@ -650,7 +652,7 @@ DRFixPoint<t>::solveNewton(Vector &y)
               if (fnorm <= flastnorm)
                 urelax_found = true;
               else
-                urelax *= std::min(0.5, flastnorm/fnorm);
+                urelax *= std::min(0.5, flastnorm / fnorm);
             }
 
           sol.add(-urelax, delta);
@@ -660,13 +662,12 @@ DRFixPoint<t>::solveNewton(Vector &y)
       converged = delta_finite && fnorm < tol;
       flastnorm = fnorm;
     }
-  while (!converged && newton_iter_last < max_newton_iter
-         && urelax > urelax_threshold);
+  while (!converged && newton_iter_last < max_newton_iter && urelax > urelax_threshold);
 
   newton_iter_total += newton_iter_last;
   if (!converged)
     newton_iter_last = 0;
-  y = const_cast<const Vector &>(sol);
+  y = const_cast<const Vector&>(sol);
   return converged;
 }
 
@@ -685,10 +686,9 @@ DRFixPoint<t>::solveNewton(Vector &y)
 
 template<Storage t>
 bool
-DRFixPoint<t>::calcFixPoint(Vector &out)
+DRFixPoint<t>::calcFixPoint(Vector& out)
 {
-  KORD_RAISE_IF(out.length() != ypart.ny(),
-                "Wrong length of out in DRFixPoint::calcFixPoint");
+  KORD_RAISE_IF(out.length() != ypart.ny(), "Wrong length of out in DRFixPoint::calcFixPoint");
 
   Vector delta(ypart.nys());
   Vector ystar(ypart.nys());
@@ -700,13 +700,12 @@ DRFixPoint<t>::calcFixPoint(Vector &out)
   bool converged = false;
   do
     {
-      if ((iter/newton_pause)*newton_pause == iter)
+      if ((iter / newton_pause) * newton_pause == iter)
         converged = solveNewton(ystar);
       if (!converged)
         {
           bigf->evalHorner(delta, ystar);
-          KORD_RAISE_IF_X(!delta.isFinite(),
-                          "NaN or Inf asserted in DRFixPoint::calcFixPoint",
+          KORD_RAISE_IF_X(!delta.isFinite(), "NaN or Inf asserted in DRFixPoint::calcFixPoint",
                           KORD_FP_NOT_FINITE);
           ystar.add(1.0, delta);
           converged = delta.getNorm() < tol;
diff --git a/mex/sources/libkorder/kord/dynamic_model.cc b/mex/sources/libkorder/kord/dynamic_model.cc
index f392144473b3830af0fb9f32126d5f42e854265f..a6733f25ab7e066e469cd2ea07153429ab6a005e 100644
--- a/mex/sources/libkorder/kord/dynamic_model.cc
+++ b/mex/sources/libkorder/kord/dynamic_model.cc
@@ -20,8 +20,8 @@
 
 #include "dynamic_model.hh"
 
-#include <iostream>
 #include <algorithm>
+#include <iostream>
 
 void
 NameList::print() const
diff --git a/mex/sources/libkorder/kord/dynamic_model.hh b/mex/sources/libkorder/kord/dynamic_model.hh
index 2171027d58796c5d480be888b5b7021088fe7a8e..b45462c4cf9dd34575104413d7c747983e2d84fd 100644
--- a/mex/sources/libkorder/kord/dynamic_model.hh
+++ b/mex/sources/libkorder/kord/dynamic_model.hh
@@ -30,8 +30,8 @@
 #ifndef DYNAMIC_MODEL_H
 #define DYNAMIC_MODEL_H
 
-#include "t_container.hh"
 #include "sparse_tensor.hh"
+#include "t_container.hh"
 
 #include "Vector.hh"
 
@@ -46,7 +46,7 @@ class NameList
 public:
   virtual ~NameList() = default;
   virtual int getNum() const = 0;
-  virtual const std::string &getName(int i) const = 0;
+  virtual const std::string& getName(int i) const = 0;
   void print() const;
 };
 
@@ -121,21 +121,22 @@ public:
   int
   numeq() const
   {
-    return nstat()+nboth()+npred()+nforw();
+    return nstat() + nboth() + npred() + nforw();
   }
 
-  virtual const NameList &getAllEndoNames() const = 0;
-  virtual const NameList &getStateNames() const = 0;
-  virtual const NameList &getExogNames() const = 0;
-  virtual const TwoDMatrix &getVcov() const = 0;
-  virtual const TensorContainer<FSSparseTensor> &getModelDerivatives() const = 0;
-  virtual const Vector &getSteady() const = 0;
-  virtual Vector &getSteady() = 0;
+  virtual const NameList& getAllEndoNames() const = 0;
+  virtual const NameList& getStateNames() const = 0;
+  virtual const NameList& getExogNames() const = 0;
+  virtual const TwoDMatrix& getVcov() const = 0;
+  virtual const TensorContainer<FSSparseTensor>& getModelDerivatives() const = 0;
+  virtual const Vector& getSteady() const = 0;
+  virtual Vector& getSteady() = 0;
 
   virtual void solveDeterministicSteady() = 0;
-  virtual void evaluateSystem(Vector &out, const ConstVector &yy, const Vector &xx) = 0;
-  virtual void evaluateSystem(Vector &out, const ConstVector &yym, const ConstVector &yy,
-                              const ConstVector &yyp, const Vector &xx) = 0;
+  virtual void evaluateSystem(Vector& out, const ConstVector& yy, const Vector& xx) = 0;
+  virtual void evaluateSystem(Vector& out, const ConstVector& yym, const ConstVector& yy,
+                              const ConstVector& yyp, const Vector& xx)
+      = 0;
   virtual void calcDerivativesAtSteady() = 0;
 };
 
diff --git a/mex/sources/libkorder/kord/faa_di_bruno.cc b/mex/sources/libkorder/kord/faa_di_bruno.cc
index 9f7e54673b09b7f83faced3a18b0f195a13943ef..8a84e1c19c9ca8cdf7181c92100fa51159d9ac93 100644
--- a/mex/sources/libkorder/kord/faa_di_bruno.cc
+++ b/mex/sources/libkorder/kord/faa_di_bruno.cc
@@ -27,9 +27,8 @@
 /* We take an opportunity to refine the stack container to avoid allocation of
    more memory than available. */
 void
-FaaDiBruno::calculate(const StackContainer<FGSTensor> &cont,
-                      const TensorContainer<FSSparseTensor> &f,
-                      FGSTensor &out)
+FaaDiBruno::calculate(const StackContainer<FGSTensor>& cont,
+                      const TensorContainer<FSSparseTensor>& f, FGSTensor& out)
 {
   out.zeros();
   for (int l = 1; l <= out.dimen(); l++)
@@ -47,8 +46,7 @@ FaaDiBruno::calculate(const StackContainer<FGSTensor> &cont,
 /* Here we just simply evaluate multAndAdd() for the dense container. There is
    no opportunity for tuning. */
 void
-FaaDiBruno::calculate(const FoldedStackContainer &cont, const FGSContainer &g,
-                      FGSTensor &out)
+FaaDiBruno::calculate(const FoldedStackContainer& cont, const FGSContainer& g, FGSTensor& out)
 {
   out.zeros();
   for (int l = 1; l <= out.dimen(); l++)
@@ -56,7 +54,7 @@ FaaDiBruno::calculate(const FoldedStackContainer &cont, const FGSContainer &g,
       long int mem = SystemResources::availableMemory();
       cont.multAndAdd(l, g, out);
       JournalRecord rec(journal);
-      int mem_mb = mem/1024/1024;
+      int mem_mb = mem / 1024 / 1024;
       rec << "dim=" << l << " avmem=" << mem_mb << endrec;
     }
 }
@@ -65,9 +63,8 @@ FaaDiBruno::calculate(const FoldedStackContainer &cont, const FGSContainer &g,
 /* This is the same as FaaDiBruno::calculate() folded sparse code. The only
    difference is that we construct unfolded fine container. */
 void
-FaaDiBruno::calculate(const StackContainer<UGSTensor> &cont,
-                      const TensorContainer<FSSparseTensor> &f,
-                      UGSTensor &out)
+FaaDiBruno::calculate(const StackContainer<UGSTensor>& cont,
+                      const TensorContainer<FSSparseTensor>& f, UGSTensor& out)
 {
   out.zeros();
   for (int l = 1; l <= out.dimen(); l++)
@@ -84,8 +81,7 @@ FaaDiBruno::calculate(const StackContainer<UGSTensor> &cont,
 // FaaDiBruno::calculate() unfolded dense code
 /* Again, no tuning opportunity here. */
 void
-FaaDiBruno::calculate(const UnfoldedStackContainer &cont, const UGSContainer &g,
-                      UGSTensor &out)
+FaaDiBruno::calculate(const UnfoldedStackContainer& cont, const UGSContainer& g, UGSTensor& out)
 {
   out.zeros();
   for (int l = 1; l <= out.dimen(); l++)
@@ -93,7 +89,7 @@ FaaDiBruno::calculate(const UnfoldedStackContainer &cont, const UGSContainer &g,
       long int mem = SystemResources::availableMemory();
       cont.multAndAdd(l, g, out);
       JournalRecord rec(journal);
-      int mem_mb = mem/1024/1024;
+      int mem_mb = mem / 1024 / 1024;
       rec << "dim=" << l << " avmem=" << mem_mb << endrec;
     }
 }
@@ -129,21 +125,21 @@ FaaDiBruno::calculate(const UnfoldedStackContainer &cont, const UGSContainer &g,
    do something. */
 
 std::tuple<int, int, int>
-FaaDiBruno::estimRefinement(const TensorDimens &tdims, int nr, int l)
+FaaDiBruno::estimRefinement(const TensorDimens& tdims, int nr, int l)
 {
   int nthreads = sthread::detach_thread_group::max_parallel_threads;
   long per_size1 = tdims.calcUnfoldMaxOffset();
   long per_size2 = static_cast<long>(std::pow(tdims.getNVS().getMax(), l));
   double lambda = 0.0;
-  long per_size = sizeof(double)*nr
-    *static_cast<long>(lambda*per_size1+(1-lambda)*per_size2);
+  long per_size
+      = sizeof(double) * nr * static_cast<long>(lambda * per_size1 + (1 - lambda) * per_size2);
   long mem = SystemResources::availableMemory();
   int max = 0;
-  if (double num_cols {static_cast<double>(mem-magic_mult*nthreads*per_size)
-                       /nthreads/sizeof(double)/nr};
+  if (double num_cols {static_cast<double>(mem - magic_mult * nthreads * per_size) / nthreads
+                       / sizeof(double) / nr};
       num_cols > 0)
     {
-      double maxd = std::pow(num_cols, 1.0/l);
+      double maxd = std::pow(num_cols, 1.0 / l);
       max = static_cast<int>(std::floor(maxd));
     }
   if (max == 0)
@@ -155,7 +151,7 @@ FaaDiBruno::estimRefinement(const TensorDimens &tdims, int nr, int l)
         rec << " (decrease number of threads)";
       rec << endrec;
     }
-  int avmem_mb = mem/1024/1024;
-  int tmpmem_mb = nthreads*per_size/1024/1024;
-  return { max, avmem_mb, tmpmem_mb };
+  int avmem_mb = mem / 1024 / 1024;
+  int tmpmem_mb = nthreads * per_size / 1024 / 1024;
+  return {max, avmem_mb, tmpmem_mb};
 }
diff --git a/mex/sources/libkorder/kord/faa_di_bruno.hh b/mex/sources/libkorder/kord/faa_di_bruno.hh
index 45c6f75919facb8b395403655998ed841bded530..1e3902b8ad020e1d259ae620b3a2e838abff8b50 100644
--- a/mex/sources/libkorder/kord/faa_di_bruno.hh
+++ b/mex/sources/libkorder/kord/faa_di_bruno.hh
@@ -32,32 +32,31 @@
 #ifndef FAA_DI_BRUNO_H
 #define FAA_DI_BRUNO_H
 
+#include "gs_tensor.hh"
 #include "journal.hh"
+#include "sparse_tensor.hh"
 #include "stack_container.hh"
 #include "t_container.hh"
-#include "sparse_tensor.hh"
-#include "gs_tensor.hh"
 
 #include <tuple>
 
 class FaaDiBruno
 {
-  Journal &journal;
+  Journal& journal;
+
 public:
-  FaaDiBruno(Journal &jr)
-    : journal(jr)
+  FaaDiBruno(Journal& jr) : journal(jr)
   {
   }
-  void calculate(const StackContainer<FGSTensor> &cont, const TensorContainer<FSSparseTensor> &f,
-                 FGSTensor &out);
-  void calculate(const FoldedStackContainer &cont, const FGSContainer &g,
-                 FGSTensor &out);
-  void calculate(const StackContainer<UGSTensor> &cont, const TensorContainer<FSSparseTensor> &f,
-                 UGSTensor &out);
-  void calculate(const UnfoldedStackContainer &cont, const UGSContainer &g,
-                 UGSTensor &out);
+  void calculate(const StackContainer<FGSTensor>& cont, const TensorContainer<FSSparseTensor>& f,
+                 FGSTensor& out);
+  void calculate(const FoldedStackContainer& cont, const FGSContainer& g, FGSTensor& out);
+  void calculate(const StackContainer<UGSTensor>& cont, const TensorContainer<FSSparseTensor>& f,
+                 UGSTensor& out);
+  void calculate(const UnfoldedStackContainer& cont, const UGSContainer& g, UGSTensor& out);
+
 protected:
-  std::tuple<int, int, int> estimRefinement(const TensorDimens &tdims, int nr, int l);
+  std::tuple<int, int, int> estimRefinement(const TensorDimens& tdims, int nr, int l);
 
   // See FaaDiBruno::calculate() folded sparse code for why we have magic_mult
   constexpr static double magic_mult = 1.5;
diff --git a/mex/sources/libkorder/kord/first_order.cc b/mex/sources/libkorder/kord/first_order.cc
index 8556fad0e0a30b20ec0c488a0a5ba6783905c2d2..7a3b95b7c5c74485a3e1e9aa4b1a4a68686bbe37 100644
--- a/mex/sources/libkorder/kord/first_order.cc
+++ b/mex/sources/libkorder/kord/first_order.cc
@@ -18,8 +18,8 @@
  * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#include "kord_exception.hh"
 #include "first_order.hh"
+#include "kord_exception.hh"
 
 #include <dynlapack.h>
 
@@ -31,9 +31,10 @@ std::mutex FirstOrder::mut;
    criterium). */
 
 lapack_int
-FirstOrder::order_eigs(const double *alphar, const double *alphai, const double *beta)
+FirstOrder::order_eigs(const double* alphar, const double* alphai, const double* beta)
 {
-  return (*alphar **alphar + *alphai **alphai < *beta **beta * qz_criterium_global * qz_criterium_global);
+  return (*alphar * *alphar + *alphai * *alphai
+          < *beta * *beta * qz_criterium_global * qz_criterium_global);
 }
 
 /* Here we solve the linear approximation. The result are the matrices
@@ -49,7 +50,7 @@ FirstOrder::order_eigs(const double *alphar, const double *alphai, const double
    and partitioning of the vector y (from object). */
 
 void
-FirstOrder::solve(const TwoDMatrix &fd)
+FirstOrder::solve(const TwoDMatrix& fd)
 {
   JournalRecordPair pa(journal);
   pa << "Recovering first order derivatives " << endrec;
@@ -144,14 +145,14 @@ FirstOrder::solve(const TwoDMatrix &fd)
   off += nu;
 
   // Form matrix D
-  lapack_int n = ypart.ny()+ypart.nboth;
+  lapack_int n = ypart.ny() + ypart.nboth;
   TwoDMatrix matD(n, n);
   matD.zeros();
   matD.place(fypzero, 0, 0);
   matD.place(fybzero, 0, ypart.npred);
-  matD.place(fyplus, 0, ypart.nys()+ypart.nstat);
+  matD.place(fyplus, 0, ypart.nys() + ypart.nstat);
   for (int i = 0; i < ypart.nboth; i++)
-    matD.get(ypart.ny()+i, ypart.npred+i) = 1.0;
+    matD.get(ypart.ny() + i, ypart.npred + i) = 1.0;
   lapack_int ldb = matD.getLD();
 
   // Form matrix E
@@ -159,9 +160,9 @@ FirstOrder::solve(const TwoDMatrix &fd)
   matE.zeros();
   matE.place(fymins, 0, 0);
   matE.place(fyszero, 0, ypart.nys());
-  matE.place(fyfzero, 0, ypart.nys()+ypart.nstat+ypart.nboth);
+  matE.place(fyfzero, 0, ypart.nys() + ypart.nstat + ypart.nboth);
   for (int i = 0; i < ypart.nboth; i++)
-    matE.get(ypart.ny()+i, ypart.nys()+ypart.nstat+i) = -1.0;
+    matE.get(ypart.ny() + i, ypart.nys() + ypart.nstat + i) = -1.0;
   matE.mult(-1.0);
   lapack_int lda = matE.getLD();
 
@@ -169,30 +170,28 @@ FirstOrder::solve(const TwoDMatrix &fd)
   TwoDMatrix vsl(n, n);
   TwoDMatrix vsr(n, n);
   lapack_int ldvsl = vsl.getLD(), ldvsr = vsr.getLD();
-  lapack_int lwork = 100*n+16;
+  lapack_int lwork = 100 * n + 16;
   Vector work(lwork);
   auto bwork = std::make_unique<lapack_int[]>(n);
   lapack_int info;
   lapack_int sdim2 = sdim;
   {
-    std::lock_guard<std::mutex> lk{mut};
+    std::lock_guard<std::mutex> lk {mut};
     qz_criterium_global = qz_criterium;
-    dgges("N", "V", "S", order_eigs, &n, matE.getData().base(), &lda,
-          matD.getData().base(), &ldb, &sdim2, alphar.base(), alphai.base(),
-          beta.base(), vsl.getData().base(), &ldvsl, vsr.getData().base(), &ldvsr,
-          work.base(), &lwork, bwork.get(), &info);
+    dgges("N", "V", "S", order_eigs, &n, matE.getData().base(), &lda, matD.getData().base(), &ldb,
+          &sdim2, alphar.base(), alphai.base(), beta.base(), vsl.getData().base(), &ldvsl,
+          vsr.getData().base(), &ldvsr, work.base(), &lwork, bwork.get(), &info);
   }
   if (info)
-    throw KordException(__FILE__, __LINE__,
-                        "DGGES returns an error in FirstOrder::solve");
+    throw KordException(__FILE__, __LINE__, "DGGES returns an error in FirstOrder::solve");
   sdim = sdim2;
   bk_cond = (sdim == ypart.nys());
 
   // Setup submatrices of Z
   ConstGeneralMatrix z11(vsr, 0, 0, ypart.nys(), ypart.nys());
-  ConstGeneralMatrix z12(vsr, 0, ypart.nys(), ypart.nys(), n-ypart.nys());
-  ConstGeneralMatrix z21(vsr, ypart.nys(), 0, n-ypart.nys(), ypart.nys());
-  ConstGeneralMatrix z22(vsr, ypart.nys(), ypart.nys(), n-ypart.nys(), n-ypart.nys());
+  ConstGeneralMatrix z12(vsr, 0, ypart.nys(), ypart.nys(), n - ypart.nys());
+  ConstGeneralMatrix z21(vsr, ypart.nys(), 0, n - ypart.nys(), ypart.nys());
+  ConstGeneralMatrix z22(vsr, ypart.nys(), ypart.nys(), n - ypart.nys(), n - ypart.nys());
 
   // Calculate derivatives of static and forward
   /* Here we calculate X=−Z₂₂⁻ᵀZ₁₂ᵀ, where X is ‘sfder’ in the code. */
@@ -214,11 +213,12 @@ FirstOrder::solve(const TwoDMatrix &fd)
   gy.place(preder, ypart.nstat, 0);
   GeneralMatrix sder(sfder, 0, 0, ypart.nstat, ypart.nys());
   gy.place(sder, 0, 0);
-  GeneralMatrix fder(sfder, ypart.nstat+ypart.nboth, 0, ypart.nforw, ypart.nys());
-  gy.place(fder, ypart.nstat+ypart.nys(), 0);
+  GeneralMatrix fder(sfder, ypart.nstat + ypart.nboth, 0, ypart.nforw, ypart.nys());
+  gy.place(fder, ypart.nstat + ypart.nys(), 0);
 
   // Check difference for derivatives of both
-  GeneralMatrix bder(const_cast<const GeneralMatrix &>(sfder), ypart.nstat, 0, ypart.nboth, ypart.nys());
+  GeneralMatrix bder(const_cast<const GeneralMatrix&>(sfder), ypart.nstat, 0, ypart.nboth,
+                     ypart.nys());
   GeneralMatrix bder2(preder, ypart.npred, 0, ypart.nboth, ypart.nys());
   bder.add(-1, bder2);
   b_error = bder.getData().getMax();
@@ -237,7 +237,7 @@ FirstOrder::solve(const TwoDMatrix &fd)
      is ‘matA’ in the code. */
   GeneralMatrix matA(ypart.ny(), ypart.ny());
   matA.zeros();
-  ConstGeneralMatrix gss(gy, ypart.nstat+ypart.npred, 0, ypart.nyss(), ypart.nys());
+  ConstGeneralMatrix gss(gy, ypart.nstat + ypart.npred, 0, ypart.nyss(), ypart.nys());
   matA.place(fyplus * gss, 0, ypart.nstat);
   ConstGeneralMatrix fyzero(fd, 0, ypart.nyss(), ypart.ny(), ypart.ny());
   matA.add(1.0, fyzero);
@@ -247,9 +247,7 @@ FirstOrder::solve(const TwoDMatrix &fd)
 
   journalEigs();
 
-  KORD_RAISE_IF_X(!bk_cond,
-                  "The model is not Blanchard-Kahn stable",
-                  KORD_MD_NOT_STABLE);
+  KORD_RAISE_IF_X(!bk_cond, "The model is not Blanchard-Kahn stable", KORD_MD_NOT_STABLE);
   if (!gy.isFinite() || !gu.isFinite())
     throw KordException(__FILE__, __LINE__,
                         "NaN or Inf asserted in first order derivatives in FirstOrder::solve()");
@@ -283,9 +281,9 @@ FirstOrder::journalEigs()
             jr << endrec;
           }
         JournalRecord jr(journal);
-        double mod = std::sqrt(alphar[i]*alphar[i]+alphai[i]*alphai[i]);
-        mod = mod/std::round(100000*std::abs(beta[i]))*100000;
-        jr << i << "\t(" << alphar[i] << "," << alphai[i] << ") / " << beta[i]
-           << "  \t" << mod << endrec;
+        double mod = std::sqrt(alphar[i] * alphar[i] + alphai[i] * alphai[i]);
+        mod = mod / std::round(100000 * std::abs(beta[i])) * 100000;
+        jr << i << "\t(" << alphar[i] << "," << alphai[i] << ") / " << beta[i] << "  \t" << mod
+           << endrec;
       }
 }
diff --git a/mex/sources/libkorder/kord/first_order.hh b/mex/sources/libkorder/kord/first_order.hh
index d68d0b2311648fa8e54c03b82160c4748bee8ee5..37ec26ef9e74188802da484610ed87c030e84eb7 100644
--- a/mex/sources/libkorder/kord/first_order.hh
+++ b/mex/sources/libkorder/kord/first_order.hh
@@ -44,10 +44,10 @@ class FirstOrder
   Vector alphai;
   Vector beta;
   double qz_criterium;
-  Journal &journal;
+  Journal& journal;
 
   // Passed to LAPACK's DGGES
-  static lapack_int order_eigs(const double *alphar, const double *alphai, const double *beta);
+  static lapack_int order_eigs(const double* alphar, const double* alphai, const double* beta);
 
   // The value of qz_criterium_global used by the order_eigs function
   /* NB: we have no choice but to use a global variable, since LAPACK won't
@@ -56,33 +56,30 @@ class FirstOrder
 
   // Protects the static qz_criterium_global
   static std::mutex mut;
+
 public:
-  FirstOrder(int num_stat, int num_pred, int num_both, int num_forw,
-             int num_u, const FSSparseTensor &f, Journal &jr, double qz_crit)
-    : ypart(num_stat, num_pred, num_both, num_forw),
-      nu(num_u),
-      gy(ypart.ny(), ypart.nys()),
-      gu(ypart.ny(), nu),
-      alphar(ypart.ny()+ypart.nboth),
-      alphai(ypart.ny()+ypart.nboth),
-      beta(ypart.ny()+ypart.nboth),
-      qz_criterium(qz_crit),
+  FirstOrder(int num_stat, int num_pred, int num_both, int num_forw, int num_u,
+             const FSSparseTensor& f, Journal& jr, double qz_crit) :
+      ypart(num_stat, num_pred, num_both, num_forw),
+      nu(num_u), gy(ypart.ny(), ypart.nys()), gu(ypart.ny(), nu), alphar(ypart.ny() + ypart.nboth),
+      alphai(ypart.ny() + ypart.nboth), beta(ypart.ny() + ypart.nboth), qz_criterium(qz_crit),
       journal(jr)
   {
     solve(FFSTensor(f));
   }
-  const TwoDMatrix &
+  const TwoDMatrix&
   getGy() const
   {
     return gy;
   }
-  const TwoDMatrix &
+  const TwoDMatrix&
   getGu() const
   {
     return gu;
   }
+
 protected:
-  void solve(const TwoDMatrix &f);
+  void solve(const TwoDMatrix& f);
   void journalEigs();
 };
 
@@ -93,15 +90,16 @@ template<Storage t>
 class FirstOrderDerivs : public ctraits<t>::Tg
 {
 public:
-  FirstOrderDerivs(const FirstOrder &fo)
-    : ctraits<t>::Tg(4)
+  FirstOrderDerivs(const FirstOrder& fo) : ctraits<t>::Tg(4)
   {
-    IntSequence nvs{fo.ypart.nys(), fo.nu, fo.nu, 1};
-    auto ten = std::make_unique<typename ctraits<t>::Ttensor>(fo.ypart.ny(), TensorDimens(Symmetry{1, 0, 0, 0}, nvs));
+    IntSequence nvs {fo.ypart.nys(), fo.nu, fo.nu, 1};
+    auto ten = std::make_unique<typename ctraits<t>::Ttensor>(
+        fo.ypart.ny(), TensorDimens(Symmetry {1, 0, 0, 0}, nvs));
     ten->zeros();
     ten->add(1.0, fo.gy);
     this->insert(std::move(ten));
-    ten = std::make_unique<typename ctraits<t>::Ttensor>(fo.ypart.ny(), TensorDimens(Symmetry{0, 1, 0, 0}, nvs));
+    ten = std::make_unique<typename ctraits<t>::Ttensor>(fo.ypart.ny(),
+                                                         TensorDimens(Symmetry {0, 1, 0, 0}, nvs));
     ten->zeros();
     ten->add(1.0, fo.gu);
     this->insert(std::move(ten));
diff --git a/mex/sources/libkorder/kord/journal.cc b/mex/sources/libkorder/kord/journal.cc
index 60f9b56d49770852709ffb64975325204afcbded..20cfb2c048eb67e856648ff60c41cd2cc0bd1195 100644
--- a/mex/sources/libkorder/kord/journal.cc
+++ b/mex/sources/libkorder/kord/journal.cc
@@ -21,30 +21,31 @@
 #include "journal.hh"
 #include "kord_exception.hh"
 
-#include <iomanip>
 #include <cmath>
 #include <ctime>
+#include <iomanip>
 #include <limits>
 #include <thread>
 
 #ifndef _WIN32
-# include <sys/time.h>     // For getrusage()
+# include <cstdlib>        // For getloadavg()
 # include <sys/resource.h> // For getrusage()
+# include <sys/time.h>     // For getrusage()
 # include <sys/utsname.h>  // For uname()
-# include <cstdlib>        // For getloadavg()
 # include <unistd.h>       // For sysconf()
 # ifdef __APPLE__
-#  include <sys/types.h>
 #  include <sys/sysctl.h>
+#  include <sys/types.h>
 # endif
 #else
 # ifndef NOMINMAX
-#  define NOMINMAX         // Do not define "min" and "max" macros
+#  define NOMINMAX // Do not define "min" and "max" macros
 # endif
-# include <windows.h>      // For GlobalMemoryStatus()
+# include <windows.h> // For GlobalMemoryStatus()
 #endif
 
-const std::chrono::time_point<std::chrono::high_resolution_clock> SystemResources::start = std::chrono::high_resolution_clock::now();
+const std::chrono::time_point<std::chrono::high_resolution_clock> SystemResources::start
+    = std::chrono::high_resolution_clock::now();
 
 #ifndef _WIN32
 long
@@ -58,11 +59,11 @@ long
 SystemResources::availableMemory()
 {
 #if !defined(_WIN32) && !defined(__APPLE__)
-  return sysconf(_SC_AVPHYS_PAGES)*pageSize();
+  return sysconf(_SC_AVPHYS_PAGES) * pageSize();
 #elif defined(__APPLE__)
   unsigned long usermem = 0;
   size_t len = sizeof usermem;
-  static int mib[2] = { CTL_HW, HW_USERMEM };
+  static int mib[2] = {CTL_HW, HW_USERMEM};
   int retval = sysctl(mib, 2, &usermem, &len, NULL, 0);
   if (retval == 0)
     return static_cast<long>(usermem);
@@ -83,8 +84,8 @@ SystemResources::SystemResources()
 #ifndef _WIN32
   struct rusage rus;
   getrusage(RUSAGE_SELF, &rus);
-  utime = rus.ru_utime.tv_sec+rus.ru_utime.tv_usec*1.0e-6;
-  stime = rus.ru_stime.tv_sec+rus.ru_stime.tv_usec*1.0e-6;
+  utime = rus.ru_utime.tv_sec + rus.ru_utime.tv_usec * 1.0e-6;
+  stime = rus.ru_stime.tv_sec + rus.ru_stime.tv_usec * 1.0e-6;
   idrss = rus.ru_idrss;
   majflt = rus.ru_majflt * pageSize();
 #else
@@ -104,7 +105,7 @@ SystemResources::SystemResources()
 }
 
 void
-SystemResources::diff(const SystemResources &pre)
+SystemResources::diff(const SystemResources& pre)
 {
   utime -= pre.utime;
   stime -= pre.stime;
@@ -114,14 +115,14 @@ SystemResources::diff(const SystemResources &pre)
 }
 
 // JournalRecord::operator<<() symmetry code
-JournalRecord &
-JournalRecord::operator<<(const IntSequence &s)
+JournalRecord&
+JournalRecord::operator<<(const IntSequence& s)
 {
   operator<<('[');
   for (int i = 0; i < s.size(); i++)
     {
       operator<<(s[i]);
-      if (i < s.size()-1)
+      if (i < s.size() - 1)
         operator<<(',');
     }
   operator<<(']');
@@ -129,49 +130,49 @@ JournalRecord::operator<<(const IntSequence &s)
 }
 
 void
-JournalRecord::writeFloatTabular(std::ostream &s, double d, int width)
+JournalRecord::writeFloatTabular(std::ostream& s, double d, int width)
 {
   // Number of digits of integer part
-  int intdigits = std::max(static_cast<int>(std::floor(log10(d))+1), 1);
+  int intdigits = std::max(static_cast<int>(std::floor(log10(d)) + 1), 1);
 
   int prec = std::max(width - 1 - intdigits, 0);
   s << std::fixed << std::setw(width) << std::setprecision(prec) << d;
 }
 
 void
-JournalRecord::writePrefix(const SystemResources &f)
+JournalRecord::writePrefix(const SystemResources& f)
 {
-  constexpr double mb = 1024*1024;
+  constexpr double mb = 1024 * 1024;
   std::ostringstream s;
   s << std::setfill('0');
   writeFloatTabular(s, f.elapsed, 7);
   s << "│" << recChar << std::setw(5) << ord << "│";
   writeFloatTabular(s, f.load_avg, 3);
   s << "│";
-  writeFloatTabular(s, f.mem_avail/mb, 5);
+  writeFloatTabular(s, f.mem_avail / mb, 5);
   s << "│      │ ";
-  for (int i = 0; i < 2*journal.getDepth(); i++)
+  for (int i = 0; i < 2 * journal.getDepth(); i++)
     s << ' ';
   prefix = s.str();
 }
 
 void
-JournalRecordPair::writePrefixForEnd(const SystemResources &f)
+JournalRecordPair::writePrefixForEnd(const SystemResources& f)
 {
-  constexpr double mb = 1024*1024;
+  constexpr double mb = 1024 * 1024;
   SystemResources difnow;
   difnow.diff(f);
   std::ostringstream s;
   s << std::setfill('0');
-  writeFloatTabular(s, f.elapsed+difnow.elapsed, 7);
+  writeFloatTabular(s, f.elapsed + difnow.elapsed, 7);
   s << "│E" << std::setw(5) << ord << "│";
   writeFloatTabular(s, difnow.load_avg, 3);
   s << "│";
-  writeFloatTabular(s, difnow.mem_avail/mb, 5);
+  writeFloatTabular(s, difnow.mem_avail / mb, 5);
   s << "│";
-  writeFloatTabular(s, difnow.majflt/mb, 6);
+  writeFloatTabular(s, difnow.majflt / mb, 6);
   s << "│ ";
-  for (int i = 0; i < 2*journal.getDepth(); i++)
+  for (int i = 0; i < 2 * journal.getDepth(); i++)
     s << ' ';
   prefix_end = s.str();
 }
@@ -186,8 +187,8 @@ JournalRecordPair::~JournalRecordPair()
   journal.flush();
 }
 
-JournalRecord &
-endrec(JournalRecord &rec)
+JournalRecord&
+endrec(JournalRecord& rec)
 {
   rec.journal << rec.prefix;
   rec.journal << rec.mes;
@@ -200,19 +201,15 @@ endrec(JournalRecord &rec)
 void
 Journal::printHeader()
 {
-  *this << "Dynare, version " << PACKAGE_VERSION << '\n'
-        << '\n'
-        << "System info: ";
+  *this << "Dynare, version " << PACKAGE_VERSION << '\n' << '\n' << "System info: ";
 #ifndef _WIN32
   utsname info;
   uname(&info);
-  *this << info.sysname << " " << info.release << " " << info.version << " "
-        << info.machine;
+  *this << info.sysname << " " << info.release << " " << info.version << " " << info.machine;
 #else
   *this << "Windows";
 #endif
-  *this << ", processors online: " << std::thread::hardware_concurrency()
-        << "\n\nStart time: ";
+  *this << ", processors online: " << std::thread::hardware_concurrency() << "\n\nStart time: ";
   std::time_t t = std::time(nullptr);
   // NB: in the date/time string, we avoid using locale-specific strings (#1751)
   *this << std::put_time(std::localtime(&t),
diff --git a/mex/sources/libkorder/kord/journal.hh b/mex/sources/libkorder/kord/journal.hh
index a6bfb095fcc78f70692133fdce49e67fb7dfb451..5e18a54146c4043763e3bc97b2740e4f68dc5733 100644
--- a/mex/sources/libkorder/kord/journal.hh
+++ b/mex/sources/libkorder/kord/journal.hh
@@ -25,11 +25,11 @@
 
 #include "int_sequence.hh"
 
+#include <chrono>
+#include <fstream>
 #include <iostream>
 #include <sstream>
-#include <fstream>
 #include <string>
-#include <chrono>
 
 /* Implement static methods for accessing some system resources. An instance of
    this class is a photograph of these resources at the time of instantiation. */
@@ -52,23 +52,23 @@ struct SystemResources
   long majflt;
 
   SystemResources();
-  void diff(const SystemResources &pre);
+  void diff(const SystemResources& pre);
 };
 
 class Journal : public std::ofstream
 {
-  int ord{0};
-  int depth{0};
+  int ord {0};
+  int depth {0};
+
 public:
-  explicit Journal(const std::string &fname)
-    : std::ofstream(fname)
+  explicit Journal(const std::string& fname) : std::ofstream(fname)
   {
     printHeader();
   }
   /* Constructor that does not initialize the std::ofstream. To be used when an
      on-disk journal is not wanted. */
   Journal() = default;
-  Journal &operator=(Journal &&) = default;
+  Journal& operator=(Journal&&) = default;
   ~Journal() override
   {
     flush();
@@ -102,63 +102,64 @@ public:
 };
 
 class JournalRecord;
-JournalRecord &endrec(JournalRecord &);
+JournalRecord& endrec(JournalRecord&);
 
 class JournalRecord
 {
 protected:
   char recChar;
   int ord;
+
 public:
-  Journal &journal;
+  Journal& journal;
   std::string prefix;
   std::string mes;
   SystemResources flash;
-  using _Tfunc = JournalRecord &(*)(JournalRecord &);
+  using _Tfunc = JournalRecord& (*)(JournalRecord&);
 
-  explicit JournalRecord(Journal &jr, char rc = 'M')
-    : recChar(rc), ord(jr.getOrd()), journal(jr)
+  explicit JournalRecord(Journal& jr, char rc = 'M') : recChar(rc), ord(jr.getOrd()), journal(jr)
   {
     writePrefix(flash);
   }
   virtual ~JournalRecord() = default;
-  JournalRecord &operator<<(const IntSequence &s);
-  JournalRecord &
+  JournalRecord& operator<<(const IntSequence& s);
+  JournalRecord&
   operator<<(_Tfunc f)
   {
     (*f)(*this);
     return *this;
   }
-  JournalRecord &
+  JournalRecord&
   operator<<(char c)
   {
     mes += c;
     return *this;
   }
-  JournalRecord &
-  operator<<(const std::string &s)
+  JournalRecord&
+  operator<<(const std::string& s)
   {
     mes += s;
     return *this;
   }
-  JournalRecord &
+  JournalRecord&
   operator<<(int i)
   {
     mes += std::to_string(i);
     return *this;
   }
-  JournalRecord &
+  JournalRecord&
   operator<<(double d)
   {
     mes += std::to_string(d);
     return *this;
   }
+
 protected:
-  void writePrefix(const SystemResources &f);
+  void writePrefix(const SystemResources& f);
   /* Writes a floating point number as a field of exactly ‘width’ characters
      large. Note that the width will not be respected if the integer part is
      too large. */
-  static void writeFloatTabular(std::ostream &s, double d, int width);
+  static void writeFloatTabular(std::ostream& s, double d, int width);
 };
 
 /*
@@ -170,15 +171,16 @@ protected:
 class JournalRecordPair : public JournalRecord
 {
   std::string prefix_end;
+
 public:
-  explicit JournalRecordPair(Journal &jr)
-    : JournalRecord(jr, 'S')
+  explicit JournalRecordPair(Journal& jr) : JournalRecord(jr, 'S')
   {
     journal.incrementDepth();
   }
   ~JournalRecordPair() override;
+
 private:
-  void writePrefixForEnd(const SystemResources &f);
+  void writePrefixForEnd(const SystemResources& f);
 };
 
 #endif
diff --git a/mex/sources/libkorder/kord/kord_exception.hh b/mex/sources/libkorder/kord/kord_exception.hh
index 1e357e8b01542fe14458739491664b943fa8bc4e..ddf8fd0bb7d3788ded3b11155a2923ad60aa285e 100644
--- a/mex/sources/libkorder/kord/kord_exception.hh
+++ b/mex/sources/libkorder/kord/kord_exception.hh
@@ -22,23 +22,23 @@
 
 /* This is a simple code defining an exception and two convenience macros. */
 
-#include <string>
 #include <iostream>
+#include <string>
 
 #ifndef KORD_EXCEPTION_H
 # define KORD_EXCEPTION_H
 
-# define KORD_RAISE(mes)                        \
-  throw KordException(__FILE__, __LINE__, mes);
+# define KORD_RAISE(mes) throw KordException(__FILE__, __LINE__, mes);
 
-# define KORD_RAISE_IF(expr, mes)                               \
-  if (expr) throw KordException(__FILE__, __LINE__, mes);
+# define KORD_RAISE_IF(expr, mes)                                                                  \
+  if (expr)                                                                                        \
+   throw KordException(__FILE__, __LINE__, mes);
 
-# define KORD_RAISE_X(mes, c)                           \
-  throw KordException(__FILE__, __LINE__, mes, c);
+# define KORD_RAISE_X(mes, c) throw KordException(__FILE__, __LINE__, mes, c);
 
-# define KORD_RAISE_IF_X(expr, mes, c)                          \
-  if (expr) throw KordException(__FILE__, __LINE__, mes, c);
+# define KORD_RAISE_IF_X(expr, mes, c)                                                             \
+  if (expr)                                                                                        \
+   throw KordException(__FILE__, __LINE__, mes, c);
 
 class KordException
 {
@@ -47,9 +47,10 @@ protected:
   int lnum;
   std::string message;
   int cd;
+
 public:
-  KordException(std::string f, int l, std::string mes, int c = 255)
-    : fname{std::move(f)}, lnum{l}, message{std::move(mes)}, cd{c}
+  KordException(std::string f, int l, std::string mes, int c = 255) :
+      fname {std::move(f)}, lnum {l}, message {std::move(mes)}, cd {c}
   {
   }
   virtual ~KordException() = default;
@@ -63,7 +64,7 @@ public:
   {
     return cd;
   }
-  const std::string &
+  const std::string&
   get_message() const
   {
     return message;
diff --git a/mex/sources/libkorder/kord/korder.cc b/mex/sources/libkorder/kord/korder.cc
index e06db1f060107b7003751332e9d6d1daa6063682..040e30050f98ed2d1c5c2ce00718477094a63ffc 100644
--- a/mex/sources/libkorder/kord/korder.cc
+++ b/mex/sources/libkorder/kord/korder.cc
@@ -18,8 +18,8 @@
  * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#include "kord_exception.hh"
 #include "korder.hh"
+#include "kord_exception.hh"
 
 /* Here we set ‘ipiv’ and ‘inv’ members of the PLUMatrix depending on its
    content. It is assumed that subclasses will call this method at the end of
@@ -30,26 +30,23 @@ PLUMatrix::calcPLU()
 {
   lapack_int info;
   lapack_int rows = nrows(), lda = ld;
-  inv = const_cast<const Vector &>(getData());
+  inv = const_cast<const Vector&>(getData());
   dgetrf(&rows, &rows, inv.base(), &lda, ipiv.data(), &info);
 }
 
 /* Here we just call the LAPACK machinery to multiply by the inverse. */
 
 void
-PLUMatrix::multInv(TwoDMatrix &m) const
+PLUMatrix::multInv(TwoDMatrix& m) const
 {
-  KORD_RAISE_IF(m.nrows() != ncols(),
-                "The matrix is not square in PLUMatrix::multInv");
+  KORD_RAISE_IF(m.nrows() != ncols(), "The matrix is not square in PLUMatrix::multInv");
   lapack_int info;
   lapack_int lda = ld;
   lapack_int mcols = m.ncols();
   lapack_int mrows = m.nrows();
   lapack_int ldb = m.getLD();
-  dgetrs("N", &mrows, &mcols, inv.base(), &lda, ipiv.data(),
-         m.getData().base(), &ldb, &info);
-  KORD_RAISE_IF(info != 0,
-                "Info!=0 in PLUMatrix::multInv");
+  dgetrs("N", &mrows, &mcols, inv.base(), &lda, ipiv.data(), m.getData().base(), &ldb, &info);
+  KORD_RAISE_IF(info != 0, "Info!=0 in PLUMatrix::multInv");
 }
 
 /* Here we construct the matrix A. Its dimension is ‘ny’, and it is
@@ -59,17 +56,17 @@ PLUMatrix::multInv(TwoDMatrix &m) const
    where the first zero spans ‘nstat’ columns, and last zero spans ‘nforw’
    columns. */
 
-MatrixA::MatrixA(const FSSparseTensor &f, const IntSequence &ss,
-                 const TwoDMatrix &gy, const PartitionY &ypart)
-  : PLUMatrix(ypart.ny())
+MatrixA::MatrixA(const FSSparseTensor& f, const IntSequence& ss, const TwoDMatrix& gy,
+                 const PartitionY& ypart) :
+    PLUMatrix(ypart.ny())
 {
   zeros();
 
-  IntSequence c{1};
+  IntSequence c {1};
   FGSTensor f_y(f, ss, c, TensorDimens(ss, c));
   add(1.0, f_y);
 
-  ConstTwoDMatrix gss_ys(ypart.nstat+ypart.npred, ypart.nyss(), gy);
+  ConstTwoDMatrix gss_ys(ypart.nstat + ypart.npred, ypart.nyss(), gy);
   c[0] = 0;
   FGSTensor f_yss(f, ss, c, TensorDimens(ss, c));
   TwoDMatrix sub(*this, ypart.nstat, ypart.nys());
@@ -85,23 +82,23 @@ MatrixA::MatrixA(const FSSparseTensor &f, const IntSequence &ss,
    It is, in fact, the matrix A plus the third summand. The first zero in the
    summand spans ‘nstat’ columns, the second zero spans ‘npred’ columns. */
 
-MatrixS::MatrixS(const FSSparseTensor &f, const IntSequence &ss,
-                 const TwoDMatrix &gy, const PartitionY &ypart)
-  : PLUMatrix(ypart.ny())
+MatrixS::MatrixS(const FSSparseTensor& f, const IntSequence& ss, const TwoDMatrix& gy,
+                 const PartitionY& ypart) :
+    PLUMatrix(ypart.ny())
 {
   zeros();
 
-  IntSequence c{1};
+  IntSequence c {1};
   FGSTensor f_y(f, ss, c, TensorDimens(ss, c));
   add(1.0, f_y);
 
-  ConstTwoDMatrix gss_ys(ypart.nstat+ypart.npred, ypart.nyss(), gy);
+  ConstTwoDMatrix gss_ys(ypart.nstat + ypart.npred, ypart.nyss(), gy);
   c[0] = 0;
   FGSTensor f_yss(f, ss, c, TensorDimens(ss, c));
   TwoDMatrix sub(*this, ypart.nstat, ypart.nys());
   sub.multAndAdd(ConstTwoDMatrix(f_yss), gss_ys);
 
-  TwoDMatrix sub2(*this, ypart.nstat+ypart.npred, ypart.nyss());
+  TwoDMatrix sub2(*this, ypart.nstat + ypart.npred, ypart.nyss());
   sub2.add(1.0, f_yss);
 
   calcPLU();
@@ -112,169 +109,169 @@ MatrixS::MatrixS(const FSSparseTensor &f, const IntSequence &ss,
    interesting here. */
 
 template<>
-ctraits<Storage::unfold>::Tg &
+ctraits<Storage::unfold>::Tg&
 KOrder::g<Storage::unfold>()
 {
   return _ug;
 }
 template<>
-const ctraits<Storage::unfold>::Tg &
+const ctraits<Storage::unfold>::Tg&
 KOrder::g<Storage::unfold>() const
 {
   return _ug;
 }
 template<>
-ctraits<Storage::fold>::Tg &
+ctraits<Storage::fold>::Tg&
 KOrder::g<Storage::fold>()
 {
   return _fg;
 }
 template<>
-const ctraits<Storage::fold>::Tg &
+const ctraits<Storage::fold>::Tg&
 KOrder::g<Storage::fold>() const
 {
   return _fg;
 }
 template<>
-ctraits<Storage::unfold>::Tgs &
+ctraits<Storage::unfold>::Tgs&
 KOrder::gs<Storage::unfold>()
 {
   return _ugs;
 }
 template<>
-const ctraits<Storage::unfold>::Tgs &
+const ctraits<Storage::unfold>::Tgs&
 KOrder::gs<Storage::unfold>() const
 {
   return _ugs;
 }
 template<>
-ctraits<Storage::fold>::Tgs &
+ctraits<Storage::fold>::Tgs&
 KOrder::gs<Storage::fold>()
 {
   return _fgs;
 }
 template<>
-const ctraits<Storage::fold>::Tgs &
+const ctraits<Storage::fold>::Tgs&
 KOrder::gs<Storage::fold>() const
 {
   return _fgs;
 }
 template<>
-ctraits<Storage::unfold>::Tgss &
+ctraits<Storage::unfold>::Tgss&
 KOrder::gss<Storage::unfold>()
 {
   return _ugss;
 }
 template<>
-const ctraits<Storage::unfold>::Tgss &
+const ctraits<Storage::unfold>::Tgss&
 KOrder::gss<Storage::unfold>() const
 {
   return _ugss;
 }
 template<>
-ctraits<Storage::fold>::Tgss &
+ctraits<Storage::fold>::Tgss&
 KOrder::gss<Storage::fold>()
 {
   return _fgss;
 }
 template<>
-const ctraits<Storage::fold>::Tgss &
+const ctraits<Storage::fold>::Tgss&
 KOrder::gss<Storage::fold>() const
 {
   return _fgss;
 }
 template<>
-ctraits<Storage::unfold>::TG &
+ctraits<Storage::unfold>::TG&
 KOrder::G<Storage::unfold>()
 {
   return _uG;
 }
 template<>
-const ctraits<Storage::unfold>::TG &
+const ctraits<Storage::unfold>::TG&
 KOrder::G<Storage::unfold>() const
 {
   return _uG;
 }
 template<>
-ctraits<Storage::fold>::TG &
+ctraits<Storage::fold>::TG&
 KOrder::G<Storage::fold>()
 {
   return _fG;
 }
 template<>
-const ctraits<Storage::fold>::TG &
+const ctraits<Storage::fold>::TG&
 KOrder::G<Storage::fold>() const
 {
   return _fG;
 }
 template<>
-ctraits<Storage::unfold>::TZstack &
+ctraits<Storage::unfold>::TZstack&
 KOrder::Zstack<Storage::unfold>()
 {
   return _uZstack;
 }
 template<>
-const ctraits<Storage::unfold>::TZstack &
+const ctraits<Storage::unfold>::TZstack&
 KOrder::Zstack<Storage::unfold>() const
 {
   return _uZstack;
 }
 template<>
-ctraits<Storage::fold>::TZstack &
+ctraits<Storage::fold>::TZstack&
 KOrder::Zstack<Storage::fold>()
 {
   return _fZstack;
 }
 template<>
-const ctraits<Storage::fold>::TZstack &
+const ctraits<Storage::fold>::TZstack&
 KOrder::Zstack<Storage::fold>() const
 {
   return _fZstack;
 }
 template<>
-ctraits<Storage::unfold>::TGstack &
+ctraits<Storage::unfold>::TGstack&
 KOrder::Gstack<Storage::unfold>()
 {
   return _uGstack;
 }
 template<>
-const ctraits<Storage::unfold>::TGstack &
+const ctraits<Storage::unfold>::TGstack&
 KOrder::Gstack<Storage::unfold>() const
 {
   return _uGstack;
 }
 template<>
-ctraits<Storage::fold>::TGstack &
+ctraits<Storage::fold>::TGstack&
 KOrder::Gstack<Storage::fold>()
 {
   return _fGstack;
 }
 template<>
-const ctraits<Storage::fold>::TGstack &
+const ctraits<Storage::fold>::TGstack&
 KOrder::Gstack<Storage::fold>() const
 {
   return _fGstack;
 }
 template<>
-ctraits<Storage::unfold>::Tm &
+ctraits<Storage::unfold>::Tm&
 KOrder::m<Storage::unfold>()
 {
   return _um;
 }
 template<>
-const ctraits<Storage::unfold>::Tm &
+const ctraits<Storage::unfold>::Tm&
 KOrder::m<Storage::unfold>() const
 {
   return _um;
 }
 template<>
-ctraits<Storage::fold>::Tm &
+ctraits<Storage::fold>::Tm&
 KOrder::m<Storage::fold>()
 {
   return _fm;
 }
 template<>
-const ctraits<Storage::fold>::Tm &
+const ctraits<Storage::fold>::Tm&
 KOrder::m<Storage::fold>() const
 {
   return _fm;
@@ -293,56 +290,43 @@ KOrder::m<Storage::fold>() const
    to comply to preconditions of performStep(). */
 
 KOrder::KOrder(int num_stat, int num_pred, int num_both, int num_forw,
-               const TensorContainer<FSSparseTensor> &fcont,
-               const TwoDMatrix &gy, const TwoDMatrix &gu, const TwoDMatrix &v,
-               Journal &jr)
-  : ypart(num_stat, num_pred, num_both, num_forw),
-    ny(ypart.ny()), nu(gu.ncols()), maxk(fcont.getMaxDim()),
-    nvs{ypart.nys(), nu, nu, 1},
-    _ug(4), _fg(4), _ugs(4), _fgs(4), _ugss(4), _fgss(4),
-    _uG(4), _fG(4),
+               const TensorContainer<FSSparseTensor>& fcont, const TwoDMatrix& gy,
+               const TwoDMatrix& gu, const TwoDMatrix& v, Journal& jr) :
+    ypart(num_stat, num_pred, num_both, num_forw),
+    ny(ypart.ny()), nu(gu.ncols()), maxk(fcont.getMaxDim()), nvs {ypart.nys(), nu, nu, 1}, _ug(4),
+    _fg(4), _ugs(4), _fgs(4), _ugss(4), _fgss(4), _uG(4), _fG(4),
     _uZstack(&_uG, ypart.nyss(), &_ug, ny, ypart.nys(), nu),
-    _fZstack(&_fG, ypart.nyss(), &_fg, ny, ypart.nys(), nu),
-    _uGstack(&_ugs, ypart.nys(), nu),
-    _fGstack(&_fgs, ypart.nys(), nu),
-    _um(maxk, v), _fm(_um), f(fcont),
-    matA(f.get(Symmetry{1}), _uZstack.getStackSizes(), gy, ypart),
-    matS(f.get(Symmetry{1}), _uZstack.getStackSizes(), gy, ypart),
-    matB(f.get(Symmetry{1}), _uZstack.getStackSizes()),
-    journal(jr)
-{
-  KORD_RAISE_IF(gy.ncols() != ypart.nys(),
-                "Wrong number of columns in gy in KOrder constructor");
-  KORD_RAISE_IF(v.ncols() != nu,
-                "Wrong number of columns of Vcov in KOrder constructor");
-  KORD_RAISE_IF(nu != v.nrows(),
-                "Wrong number of rows of Vcov in KOrder constructor");
-  KORD_RAISE_IF(maxk < 2,
-                "Order of approximation must be at least 2 in KOrder constructor");
-  KORD_RAISE_IF(gy.nrows() != ypart.ny(),
-                "Wrong number of rows in gy in KOrder constructor");
-  KORD_RAISE_IF(gu.nrows() != ypart.ny(),
-                "Wrong number of rows in gu in KOrder constructor");
-  KORD_RAISE_IF(gu.ncols() != nu,
-                "Wrong number of columns in gu in KOrder constructor");
+    _fZstack(&_fG, ypart.nyss(), &_fg, ny, ypart.nys(), nu), _uGstack(&_ugs, ypart.nys(), nu),
+    _fGstack(&_fgs, ypart.nys(), nu), _um(maxk, v), _fm(_um), f(fcont),
+    matA(f.get(Symmetry {1}), _uZstack.getStackSizes(), gy, ypart),
+    matS(f.get(Symmetry {1}), _uZstack.getStackSizes(), gy, ypart),
+    matB(f.get(Symmetry {1}), _uZstack.getStackSizes()), journal(jr)
+{
+  KORD_RAISE_IF(gy.ncols() != ypart.nys(), "Wrong number of columns in gy in KOrder constructor");
+  KORD_RAISE_IF(v.ncols() != nu, "Wrong number of columns of Vcov in KOrder constructor");
+  KORD_RAISE_IF(nu != v.nrows(), "Wrong number of rows of Vcov in KOrder constructor");
+  KORD_RAISE_IF(maxk < 2, "Order of approximation must be at least 2 in KOrder constructor");
+  KORD_RAISE_IF(gy.nrows() != ypart.ny(), "Wrong number of rows in gy in KOrder constructor");
+  KORD_RAISE_IF(gu.nrows() != ypart.ny(), "Wrong number of rows in gu in KOrder constructor");
+  KORD_RAISE_IF(gu.ncols() != nu, "Wrong number of columns in gu in KOrder constructor");
 
   // Put g_y and gᵤ in the container
   /* Note that g_σ is zero by construction and we do not insert it to the
      container. We insert a new physical copies. */
-  auto tgy = std::make_unique<UGSTensor>(ny, TensorDimens(Symmetry{1, 0, 0, 0}, nvs));
+  auto tgy = std::make_unique<UGSTensor>(ny, TensorDimens(Symmetry {1, 0, 0, 0}, nvs));
   tgy->getData() = gy.getData();
   insertDerivative<Storage::unfold>(std::move(tgy));
-  auto tgu = std::make_unique<UGSTensor>(ny, TensorDimens(Symmetry{0, 1, 0, 0}, nvs));
+  auto tgu = std::make_unique<UGSTensor>(ny, TensorDimens(Symmetry {0, 1, 0, 0}, nvs));
   tgu->getData() = gu.getData();
   insertDerivative<Storage::unfold>(std::move(tgu));
 
   // Put G_y, G_u and G_u′ in the container
   /* Also note that since g_σ is zero, so is G_σ. */
-  auto tGy = faaDiBrunoG<Storage::unfold>(Symmetry{1, 0, 0, 0});
+  auto tGy = faaDiBrunoG<Storage::unfold>(Symmetry {1, 0, 0, 0});
   G<Storage::unfold>().insert(std::move(tGy));
-  auto tGu = faaDiBrunoG<Storage::unfold>(Symmetry{0, 1, 0, 0});
+  auto tGu = faaDiBrunoG<Storage::unfold>(Symmetry {0, 1, 0, 0});
   G<Storage::unfold>().insert(std::move(tGu));
-  auto tGup = faaDiBrunoG<Storage::unfold>(Symmetry{0, 0, 1, 0});
+  auto tGup = faaDiBrunoG<Storage::unfold>(Symmetry {0, 0, 1, 0});
   G<Storage::unfold>().insert(std::move(tGup));
 }
 
@@ -361,19 +345,16 @@ KOrder::KOrder(int num_stat, int num_pred, int num_both, int num_forw,
 
 template<>
 void
-KOrder::sylvesterSolve<Storage::unfold>(ctraits<Storage::unfold>::Ttensor &der) const
+KOrder::sylvesterSolve<Storage::unfold>(ctraits<Storage::unfold>::Ttensor& der) const
 {
   JournalRecordPair pa(journal);
   pa << "Sylvester equation for dimension = " << der.getSym()[0] << endrec;
   if (ypart.nys() > 0 && ypart.nyss() > 0)
     {
-      KORD_RAISE_IF(!der.isFinite(),
-                    "RHS of Sylverster is not finite");
-      TwoDMatrix gs_y(gs<Storage::unfold>().get(Symmetry{1, 0, 0, 0}));
-      GeneralSylvester sylv(der.getSym()[0], ny, ypart.nys(),
-                            ypart.nstat+ypart.npred,
-                            matA.getData(), matB.getData(),
-                            gs_y.getData(), der.getData());
+      KORD_RAISE_IF(!der.isFinite(), "RHS of Sylverster is not finite");
+      TwoDMatrix gs_y(gs<Storage::unfold>().get(Symmetry {1, 0, 0, 0}));
+      GeneralSylvester sylv(der.getSym()[0], ny, ypart.nys(), ypart.nstat + ypart.npred,
+                            matA.getData(), matB.getData(), gs_y.getData(), der.getData());
       sylv.solve();
     }
   else if (ypart.nys() > 0 && ypart.nyss() == 0)
@@ -387,12 +368,12 @@ KOrder::sylvesterSolve<Storage::unfold>(ctraits<Storage::unfold>::Ttensor &der)
 
 template<>
 void
-KOrder::sylvesterSolve<Storage::fold>(ctraits<Storage::fold>::Ttensor &der) const
+KOrder::sylvesterSolve<Storage::fold>(ctraits<Storage::fold>::Ttensor& der) const
 {
   ctraits<Storage::unfold>::Ttensor tmp(der);
   sylvesterSolve<Storage::unfold>(tmp);
   ctraits<Storage::fold>::Ttensor ftmp(tmp);
-  der.getData() = const_cast<const Vector &>(ftmp.getData());
+  der.getData() = const_cast<const Vector&>(ftmp.getData());
 }
 
 void
@@ -403,7 +384,7 @@ KOrder::switchToFolded()
 
   int maxdim = g<Storage::unfold>().getMaxDim();
   for (int dim = 1; dim <= maxdim; dim++)
-    for (auto &si : SymmetrySet(dim, 4))
+    for (auto& si : SymmetrySet(dim, 4))
       {
         if (si[2] == 0 && g<Storage::unfold>().check(si))
           {
diff --git a/mex/sources/libkorder/kord/korder.hh b/mex/sources/libkorder/kord/korder.hh
index d6dcca0ad364a69285181134f49cd16a2d577f3c..8b9b2d8780d9c554b0ecda330027591769c0f078 100644
--- a/mex/sources/libkorder/kord/korder.hh
+++ b/mex/sources/libkorder/kord/korder.hh
@@ -41,19 +41,19 @@
 #ifndef KORDER_H
 #define KORDER_H
 
-#include "int_sequence.hh"
+#include "faa_di_bruno.hh"
 #include "fs_tensor.hh"
 #include "gs_tensor.hh"
-#include "t_container.hh"
-#include "stack_container.hh"
-#include "normal_moments.hh"
-#include "t_polynomial.hh"
-#include "faa_di_bruno.hh"
+#include "int_sequence.hh"
 #include "journal.hh"
+#include "normal_moments.hh"
 #include "pascal_triangle.hh"
+#include "stack_container.hh"
+#include "t_container.hh"
+#include "t_polynomial.hh"
 
-#include "kord_exception.hh"
 #include "GeneralSylvester.hh"
+#include "kord_exception.hh"
 
 #include <dynlapack.h>
 
@@ -61,7 +61,11 @@
 #include <type_traits>
 
 // The enum class passed as template parameter for many data structures
-enum class Storage { fold, unfold };
+enum class Storage
+{
+  fold,
+  unfold
+};
 
 /* In ‘ctraits’ we define a number of types. We have a type for tensor Ttensor,
    and types for each pair of folded/unfolded containers used as a member in
@@ -90,8 +94,10 @@ public:
   using TGstack = std::conditional_t<type == Storage::fold, FoldedGContainer, UnfoldedGContainer>;
   using Tm = std::conditional_t<type == Storage::fold, FNormalMoments, UNormalMoments>;
   using Tpol = std::conditional_t<type == Storage::fold, FTensorPolynomial, UTensorPolynomial>;
-  using TZXstack = std::conditional_t<type == Storage::fold, FoldedZXContainer, UnfoldedZXContainer>;
-  using TGXstack = std::conditional_t<type == Storage::fold, FoldedGXContainer, UnfoldedGXContainer>;
+  using TZXstack
+      = std::conditional_t<type == Storage::fold, FoldedZXContainer, UnfoldedZXContainer>;
+  using TGXstack
+      = std::conditional_t<type == Storage::fold, FoldedGXContainer, UnfoldedGXContainer>;
 };
 
 /* The PartitionY class defines the partitioning of state variables y. The
@@ -117,27 +123,27 @@ struct PartitionY
   const int npred;
   const int nboth;
   const int nforw;
-  PartitionY() : PartitionY(0,0,0,0) {}
-  PartitionY(int num_stat, int num_pred,
-             int num_both, int num_forw)
-    : nstat(num_stat), npred(num_pred),
-      nboth(num_both), nforw(num_forw)
+  PartitionY() : PartitionY(0, 0, 0, 0)
+  {
+  }
+  PartitionY(int num_stat, int num_pred, int num_both, int num_forw) :
+      nstat(num_stat), npred(num_pred), nboth(num_both), nforw(num_forw)
   {
   }
   int
   ny() const
   {
-    return nstat+npred+nboth+nforw;
+    return nstat + npred + nboth + nforw;
   }
   int
   nys() const
   {
-    return npred+nboth;
+    return npred + nboth;
   }
   int
   nyss() const
   {
-    return nboth+nforw;
+    return nboth + nforw;
   }
 };
 
@@ -151,16 +157,15 @@ struct PartitionY
 class PLUMatrix : public TwoDMatrix
 {
 public:
-  PLUMatrix(int n)
-    : TwoDMatrix(n, n),
-      inv(nrows()*ncols()),
-      ipiv(nrows())
+  PLUMatrix(int n) : TwoDMatrix(n, n), inv(nrows() * ncols()), ipiv(nrows())
   {
   }
-  void multInv(TwoDMatrix &m) const;
+  void multInv(TwoDMatrix& m) const;
+
 private:
   Vector inv;
   std::vector<lapack_int> ipiv;
+
 protected:
   void calcPLU();
 };
@@ -171,8 +176,8 @@ protected:
 class MatrixA : public PLUMatrix
 {
 public:
-  MatrixA(const FSSparseTensor &f, const IntSequence &ss,
-          const TwoDMatrix &gy, const PartitionY &ypart);
+  MatrixA(const FSSparseTensor& f, const IntSequence& ss, const TwoDMatrix& gy,
+          const PartitionY& ypart);
 };
 
 /* The class MatrixS slightly differs from MatrixA. It is used for
@@ -182,8 +187,8 @@ public:
 class MatrixS : public PLUMatrix
 {
 public:
-  MatrixS(const FSSparseTensor &f, const IntSequence &ss,
-          const TwoDMatrix &gy, const PartitionY &ypart);
+  MatrixS(const FSSparseTensor& f, const IntSequence& ss, const TwoDMatrix& gy,
+          const PartitionY& ypart);
 };
 
 /* The B matrix is equal to [f_y**₊]. We have just a constructor. */
@@ -191,9 +196,8 @@ public:
 class MatrixB : public TwoDMatrix
 {
 public:
-  MatrixB(const FSSparseTensor &f, const IntSequence &ss)
-    : TwoDMatrix(FGSTensor(f, ss, IntSequence(1, 0),
-                           TensorDimens(ss, IntSequence(1, 0))))
+  MatrixB(const FSSparseTensor& f, const IntSequence& ss) :
+      TwoDMatrix(FGSTensor(f, ss, IntSequence(1, 0), TensorDimens(ss, IntSequence(1, 0))))
   {
   }
 };
@@ -246,7 +250,7 @@ protected:
 
   /* Dynamic model derivatives: just a reference to the container of sparse
      tensors of the system derivatives, lives outside the class */
-  const TensorContainer<FSSparseTensor> &f;
+  const TensorContainer<FSSparseTensor>& f;
 
   /* Matrices: matrix A, matrix S, and matrix B, see MatrixA and MatrixB class
      declarations */
@@ -258,46 +262,46 @@ protected:
      containers. We declare template methods for accessing containers depending
      on ‘fold’ and ‘unfold’ flag, we implement their specializations*/
   template<Storage t>
-  typename ctraits<t>::Tg &g();
+  typename ctraits<t>::Tg& g();
   template<Storage t>
-  const typename ctraits<t>::Tg &g() const;
+  const typename ctraits<t>::Tg& g() const;
 
   template<Storage t>
-  typename ctraits<t>::Tgs &gs();
+  typename ctraits<t>::Tgs& gs();
   template<Storage t>
-  const typename ctraits<t>::Tgs &gs() const;
+  const typename ctraits<t>::Tgs& gs() const;
 
   template<Storage t>
-  typename ctraits<t>::Tgss &gss();
+  typename ctraits<t>::Tgss& gss();
   template<Storage t>
-  const typename ctraits<t>::Tgss &gss() const;
+  const typename ctraits<t>::Tgss& gss() const;
 
   template<Storage t>
-  typename ctraits<t>::TG &G();
+  typename ctraits<t>::TG& G();
   template<Storage t>
-  const typename ctraits<t>::TG &G() const;
+  const typename ctraits<t>::TG& G() const;
 
   template<Storage t>
-  typename ctraits<t>::TZstack &Zstack();
+  typename ctraits<t>::TZstack& Zstack();
   template<Storage t>
-  const typename ctraits<t>::TZstack &Zstack() const;
+  const typename ctraits<t>::TZstack& Zstack() const;
 
   template<Storage t>
-  typename ctraits<t>::TGstack &Gstack();
+  typename ctraits<t>::TGstack& Gstack();
   template<Storage t>
-  const typename ctraits<t>::TGstack &Gstack() const;
+  const typename ctraits<t>::TGstack& Gstack() const;
 
   template<Storage t>
-  typename ctraits<t>::Tm &m();
+  typename ctraits<t>::Tm& m();
   template<Storage t>
-  const typename ctraits<t>::Tm &m() const;
+  const typename ctraits<t>::Tm& m() const;
+
+  Journal& journal;
 
-  Journal &journal;
 public:
   KOrder(int num_stat, int num_pred, int num_both, int num_forw,
-         const TensorContainer<FSSparseTensor> &fcont,
-         const TwoDMatrix &gy, const TwoDMatrix &gu, const TwoDMatrix &v,
-         Journal &jr);
+         const TensorContainer<FSSparseTensor>& fcont, const TwoDMatrix& gy, const TwoDMatrix& gu,
+         const TwoDMatrix& v, Journal& jr);
 
   /* Performs k-order step provided that k=2 or the k−1-th step has been
      run, this is the core method */
@@ -312,22 +316,22 @@ public:
   template<Storage t>
   Vector calcStochShift(int order, double sigma) const;
   void switchToFolded();
-  const PartitionY &
+  const PartitionY&
   getPartY() const
   {
     return ypart;
   }
-  const FGSContainer &
+  const FGSContainer&
   getFoldDers() const
   {
     return _fg;
   }
-  const UGSContainer &
+  const UGSContainer&
   getUnfoldDers() const
   {
     return _ug;
   }
-  const FGSContainer &
+  const FGSContainer&
   getFoldDersS() const
   {
     return _fgs;
@@ -337,6 +341,7 @@ public:
   {
     return i % 2 == 0;
   }
+
 protected:
   /* Inserts a g derivative to the g container and also creates subtensors and
      insert them to g_y* and g_y** containers */
@@ -345,17 +350,17 @@ protected:
 
   /* Solves the sylvester equation (templated fold, and unfold) */
   template<Storage t>
-  void sylvesterSolve(typename ctraits<t>::Ttensor &der) const;
+  void sylvesterSolve(typename ctraits<t>::Ttensor& der) const;
 
   /* Calculates derivatives of F by Faà Di Bruno for the sparse container of
      system derivatives and Z stack container */
   template<Storage t>
-  std::unique_ptr<typename ctraits<t>::Ttensor> faaDiBrunoZ(const Symmetry &sym) const;
+  std::unique_ptr<typename ctraits<t>::Ttensor> faaDiBrunoZ(const Symmetry& sym) const;
 
   /* Calculates derivatives of G by Faà Di Bruno for the dense container g**
      and G stack */
   template<Storage t>
-  std::unique_ptr<typename ctraits<t>::Ttensor> faaDiBrunoG(const Symmetry &sym) const;
+  std::unique_ptr<typename ctraits<t>::Ttensor> faaDiBrunoG(const Symmetry& sym) const;
 
   // Recovers g_y*ⁱ
   template<Storage t>
@@ -402,8 +407,9 @@ KOrder::insertDerivative(std::unique_ptr<typename ctraits<t>::Ttensor> der)
 {
   auto der_ptr = der.get();
   g<t>().insert(std::move(der));
-  gs<t>().insert(std::make_unique<typename ctraits<t>::Ttensor>(ypart.nstat, ypart.nys(), *der_ptr));
-  gss<t>().insert(std::make_unique<typename ctraits<t>::Ttensor>(ypart.nstat+ypart.npred,
+  gs<t>().insert(
+      std::make_unique<typename ctraits<t>::Ttensor>(ypart.nstat, ypart.nys(), *der_ptr));
+  gss<t>().insert(std::make_unique<typename ctraits<t>::Ttensor>(ypart.nstat + ypart.npred,
                                                                  ypart.nyss(), *der_ptr));
 }
 
@@ -417,7 +423,7 @@ KOrder::insertDerivative(std::unique_ptr<typename ctraits<t>::Ttensor> der)
 
 template<Storage t>
 std::unique_ptr<typename ctraits<t>::Ttensor>
-KOrder::faaDiBrunoZ(const Symmetry &sym) const
+KOrder::faaDiBrunoZ(const Symmetry& sym) const
 {
   JournalRecordPair pa(journal);
   pa << "Faà Di Bruno Z container for " << sym << endrec;
@@ -431,7 +437,7 @@ KOrder::faaDiBrunoZ(const Symmetry &sym) const
 
 template<Storage t>
 std::unique_ptr<typename ctraits<t>::Ttensor>
-KOrder::faaDiBrunoG(const Symmetry &sym) const
+KOrder::faaDiBrunoG(const Symmetry& sym) const
 {
   JournalRecordPair pa(journal);
   pa << "Faà Di Bruno G container for " << sym << endrec;
@@ -456,7 +462,7 @@ template<Storage t>
 void
 KOrder::recover_y(int i)
 {
-  Symmetry sym{i, 0, 0, 0};
+  Symmetry sym {i, 0, 0, 0};
   JournalRecordPair pa(journal);
   pa << "Recovering symmetry " << sym << endrec;
 
@@ -471,9 +477,9 @@ KOrder::recover_y(int i)
 
   insertDerivative<t>(std::move(g_yi));
 
-  auto &gss_y = gss<t>().get(Symmetry{1, 0, 0, 0});
+  auto& gss_y = gss<t>().get(Symmetry {1, 0, 0, 0});
   gs<t>().multAndAdd(gss_y, *G_yi_ptr);
-  auto &gss_yi = gss<t>().get(sym);
+  auto& gss_yi = gss<t>().get(sym);
   gs<t>().multAndAdd(gss_yi, *G_yi_ptr);
 }
 
@@ -490,7 +496,7 @@ template<Storage t>
 void
 KOrder::recover_yu(int i, int j)
 {
-  Symmetry sym{i, j, 0, 0};
+  Symmetry sym {i, j, 0, 0};
   JournalRecordPair pa(journal);
   pa << "Recovering symmetry " << sym << endrec;
 
@@ -503,7 +509,7 @@ KOrder::recover_yu(int i, int j)
   matA.multInv(*g_yiuj);
   insertDerivative<t>(std::move(g_yiuj));
 
-  gs<t>().multAndAdd(gss<t>().get(Symmetry{1, 0, 0, 0}), *G_yiuj_ptr);
+  gs<t>().multAndAdd(gss<t>().get(Symmetry {1, 0, 0, 0}), *G_yiuj_ptr);
 }
 
 /* Here we solve [F_yⁱσʲ]+[Dᵢⱼ]+[Eᵢⱼ]=0 to obtain g_yⁱσʲ. We calculate
@@ -523,7 +529,7 @@ template<Storage t>
 void
 KOrder::recover_ys(int i, int j)
 {
-  Symmetry sym{i, 0, 0, j};
+  Symmetry sym {i, 0, 0, j};
   JournalRecordPair pa(journal);
   pa << "Recovering symmetry " << sym << endrec;
 
@@ -555,7 +561,7 @@ KOrder::recover_ys(int i, int j)
       insertDerivative<t>(std::move(g_yisj));
 
       Gstack<t>().multAndAdd(1, gss<t>(), *G_yisj_ptr);
-      Gstack<t>().multAndAdd(i+j, gss<t>(), *G_yisj_ptr);
+      Gstack<t>().multAndAdd(i + j, gss<t>(), *G_yisj_ptr);
     }
 }
 
@@ -576,7 +582,7 @@ template<Storage t>
 void
 KOrder::recover_yus(int i, int j, int k)
 {
-  Symmetry sym{i, j, 0, k};
+  Symmetry sym {i, j, 0, k};
   JournalRecordPair pa(journal);
   pa << "Recovering symmetry " << sym << endrec;
 
@@ -634,7 +640,7 @@ template<Storage t>
 void
 KOrder::recover_s(int i)
 {
-  Symmetry sym{0, 0, 0, i};
+  Symmetry sym {0, 0, 0, i};
   JournalRecordPair pa(journal);
   pa << "Recovering symmetry " << sym << endrec;
 
@@ -677,9 +683,9 @@ void
 KOrder::fillG(int i, int j, int k)
 {
   for (int m = 1; m <= k; m++)
-    if (is_even(k-m))
+    if (is_even(k - m))
       {
-        auto G_yiujupms = faaDiBrunoG<t>(Symmetry{i, j, m, k-m});
+        auto G_yiujupms = faaDiBrunoG<t>(Symmetry {i, j, m, k - m});
         G<t>().insert(std::move(G_yiujupms));
       }
 }
@@ -694,12 +700,12 @@ template<Storage t>
 typename ctraits<t>::Ttensor
 KOrder::calcD_ijk(int i, int j, int k) const
 {
-  typename ctraits<t>::Ttensor res(ny, TensorDimens(Symmetry{i, j, 0, 0}, nvs));
+  typename ctraits<t>::Ttensor res(ny, TensorDimens(Symmetry {i, j, 0, 0}, nvs));
   res.zeros();
   if (is_even(k))
     {
-      auto tmp = faaDiBrunoZ<t>(Symmetry{i, j, k, 0});
-      tmp->contractAndAdd(2, res, m<t>().get(Symmetry{k}));
+      auto tmp = faaDiBrunoZ<t>(Symmetry {i, j, k, 0});
+      tmp->contractAndAdd(2, res, m<t>().get(Symmetry {k}));
     }
   return res;
 }
@@ -714,13 +720,13 @@ template<Storage t>
 typename ctraits<t>::Ttensor
 KOrder::calcE_ijk(int i, int j, int k) const
 {
-  typename ctraits<t>::Ttensor res(ny, TensorDimens(Symmetry{i, j, 0, 0}, nvs));
+  typename ctraits<t>::Ttensor res(ny, TensorDimens(Symmetry {i, j, 0, 0}, nvs));
   res.zeros();
-  for (int n = 2; n <= k-1; n += 2)
+  for (int n = 2; n <= k - 1; n += 2)
     {
-      auto tmp = faaDiBrunoZ<t>(Symmetry{i, j, n, k-n});
+      auto tmp = faaDiBrunoZ<t>(Symmetry {i, j, n, k - n});
       tmp->mult(static_cast<double>(PascalTriangle::noverk(k, n)));
-      tmp->contractAndAdd(2, res, m<t>().get(Symmetry{n}));
+      tmp->contractAndAdd(2, res, m<t>().get(Symmetry {n}));
     }
   return res;
 }
@@ -777,25 +783,24 @@ template<Storage t>
 void
 KOrder::performStep(int order)
 {
-  KORD_RAISE_IF(order-1 != g<t>().getMaxDim(),
-                "Wrong order for KOrder::performStep");
+  KORD_RAISE_IF(order - 1 != g<t>().getMaxDim(), "Wrong order for KOrder::performStep");
   JournalRecordPair pa(journal);
   pa << "Performing step for order = " << order << endrec;
 
   recover_y<t>(order);
 
   for (int i = 0; i < order; i++)
-    recover_yu<t>(i, order-i);
+    recover_yu<t>(i, order - i);
 
   for (int j = 1; j < order; j++)
     {
-      for (int i = j-1; i >= 1; i--)
-        recover_yus<t>(order-j, i, j-i);
-      recover_ys<t>(order-j, j);
+      for (int i = j - 1; i >= 1; i--)
+        recover_yus<t>(order - j, i, j - i);
+      recover_ys<t>(order - j, j);
     }
 
-  for (int i = order-1; i >= 1; i--)
-    recover_yus<t>(0, i, order-i);
+  for (int i = order - 1; i >= 1; i--)
+    recover_yus<t>(0, i, order - i);
 
   recover_s<t>(order);
 }
@@ -808,8 +813,7 @@ template<Storage t>
 double
 KOrder::check(int dim) const
 {
-  KORD_RAISE_IF(dim > g<t>().getMaxDim(),
-                "Wrong dimension for KOrder::check");
+  KORD_RAISE_IF(dim > g<t>().getMaxDim(), "Wrong dimension for KOrder::check");
   JournalRecordPair pa(journal);
   pa << "Checking residuals for order = " << dim << endrec;
 
@@ -818,7 +822,7 @@ KOrder::check(int dim) const
   // Check for F_yⁱuʲ=0
   for (int i = 0; i <= dim; i++)
     {
-      Symmetry sym{dim-i, i, 0, 0};
+      Symmetry sym {dim - i, i, 0, 0};
       auto r = faaDiBrunoZ<t>(sym);
       double err = r->getData().getMax();
       JournalRecord(journal) << "\terror for symmetry " << sym << "\tis " << err << endrec;
@@ -826,14 +830,14 @@ KOrder::check(int dim) const
     }
 
   // Check for F_yⁱuʲu′ᵏ+Dᵢⱼₖ+Eᵢⱼₖ=0
-  for (auto &si : SymmetrySet(dim, 3))
+  for (auto& si : SymmetrySet(dim, 3))
     {
       int i = si[0];
       int j = si[1];
       int k = si[2];
-      if (i+j > 0 && k > 0)
+      if (i + j > 0 && k > 0)
         {
-          Symmetry sym{i, j, 0, k};
+          Symmetry sym {i, j, 0, k};
           auto r = faaDiBrunoZ<t>(sym);
           auto D_ijk = calcD_ijk<t>(i, j, k);
           r->add(1.0, D_ijk);
@@ -846,13 +850,13 @@ KOrder::check(int dim) const
     }
 
   // Check for F_σⁱ+Dᵢ+Eᵢ=0
-  auto r = faaDiBrunoZ<t>(Symmetry{0, 0, 0, dim});
+  auto r = faaDiBrunoZ<t>(Symmetry {0, 0, 0, dim});
   auto D_k = calcD_k<t>(dim);
   r->add(1.0, D_k);
   auto E_k = calcE_k<t>(dim);
   r->add(1.0, E_k);
   double err = r->getData().getMax();
-  Symmetry sym{0, 0, 0, dim};
+  Symmetry sym {0, 0, 0, dim};
   JournalRecord(journal) << "\terror for symmetry " << sym << "\tis " << err << endrec;
   maxerror = std::max(err, maxerror);
 
@@ -870,7 +874,7 @@ KOrder::calcStochShift(int order, double sigma) const
     if (is_even(j))
       {
         auto ten = calcD_k<t>(j);
-        res.add(std::pow(sigma, j)/jfac, ten.getData());
+        res.add(std::pow(sigma, j) / jfac, ten.getData());
       }
   return res;
 }
diff --git a/mex/sources/libkorder/kord/korder_stoch.cc b/mex/sources/libkorder/kord/korder_stoch.cc
index def68885a3452535cf4acfb68454f6fee605339d..418765326b1f730ce236aa62719565a18c80cbc0 100644
--- a/mex/sources/libkorder/kord/korder_stoch.cc
+++ b/mex/sources/libkorder/kord/korder_stoch.cc
@@ -23,13 +23,13 @@
 /* Same as MatrixA constructor, but the submatrix ‘gss_ys’ is passed
    directly. */
 
-MatrixAA::MatrixAA(const FSSparseTensor &f, const IntSequence &ss,
-                   const TwoDMatrix &gss_ys, const PartitionY &ypart)
-  : PLUMatrix(ypart.ny())
+MatrixAA::MatrixAA(const FSSparseTensor& f, const IntSequence& ss, const TwoDMatrix& gss_ys,
+                   const PartitionY& ypart) :
+    PLUMatrix(ypart.ny())
 {
   zeros();
 
-  IntSequence c{1};
+  IntSequence c {1};
   FGSTensor f_y(f, ss, c, TensorDimens(ss, c));
   add(1.0, f_y);
 
@@ -42,168 +42,158 @@ MatrixAA::MatrixAA(const FSSparseTensor &f, const IntSequence &ss,
 }
 
 // KOrderStoch folded constructor code
-KOrderStoch::KOrderStoch(const PartitionY &yp, int nu,
-                         const TensorContainer<FSSparseTensor> &fcont,
-                         const FGSContainer &hh, Journal &jr)
-  : nvs{yp.nys(), nu, nu, 1}, ypart(yp), journal(jr),
-    _ug(4), _fg(4), _ugs(4), _fgs(4), _uG(4), _fG(4),
-    _uh(nullptr), _fh(&hh),
-    _uZstack(&_uG, ypart.nyss(), &_ug, ypart.ny(), ypart.nys(), nu),
+KOrderStoch::KOrderStoch(const PartitionY& yp, int nu, const TensorContainer<FSSparseTensor>& fcont,
+                         const FGSContainer& hh, Journal& jr) :
+    nvs {yp.nys(), nu, nu, 1},
+    ypart(yp), journal(jr), _ug(4), _fg(4), _ugs(4), _fgs(4), _uG(4), _fG(4), _uh(nullptr),
+    _fh(&hh), _uZstack(&_uG, ypart.nyss(), &_ug, ypart.ny(), ypart.nys(), nu),
     _fZstack(&_fG, ypart.nyss(), &_fg, ypart.ny(), ypart.nys(), nu),
-    _uGstack(&_ugs, ypart.nys(), nu),
-    _fGstack(&_fgs, ypart.nys(), nu),
-    f(fcont),
-    matA(fcont.get(Symmetry{1}), _uZstack.getStackSizes(), hh.get(Symmetry{1, 0, 0, 0}),
-         ypart)
+    _uGstack(&_ugs, ypart.nys(), nu), _fGstack(&_fgs, ypart.nys(), nu), f(fcont),
+    matA(fcont.get(Symmetry {1}), _uZstack.getStackSizes(), hh.get(Symmetry {1, 0, 0, 0}), ypart)
 {
 }
 
 // KOrderStoch unfolded constructor code
-KOrderStoch::KOrderStoch(const PartitionY &yp, int nu,
-                         const TensorContainer<FSSparseTensor> &fcont,
-                         const UGSContainer &hh, Journal &jr)
-  : nvs{yp.nys(), nu, nu, 1}, ypart(yp), journal(jr),
-    _ug(4), _fg(4), _ugs(4), _fgs(4), _uG(4), _fG(4),
-    _uh(&hh), _fh(nullptr),
-    _uZstack(&_uG, ypart.nyss(), &_ug, ypart.ny(), ypart.nys(), nu),
+KOrderStoch::KOrderStoch(const PartitionY& yp, int nu, const TensorContainer<FSSparseTensor>& fcont,
+                         const UGSContainer& hh, Journal& jr) :
+    nvs {yp.nys(), nu, nu, 1},
+    ypart(yp), journal(jr), _ug(4), _fg(4), _ugs(4), _fgs(4), _uG(4), _fG(4), _uh(&hh),
+    _fh(nullptr), _uZstack(&_uG, ypart.nyss(), &_ug, ypart.ny(), ypart.nys(), nu),
     _fZstack(&_fG, ypart.nyss(), &_fg, ypart.ny(), ypart.nys(), nu),
-    _uGstack(&_ugs, ypart.nys(), nu),
-    _fGstack(&_fgs, ypart.nys(), nu),
-    f(fcont),
-    matA(fcont.get(Symmetry{1}), _uZstack.getStackSizes(), hh.get(Symmetry{1, 0, 0, 0}),
-         ypart)
+    _uGstack(&_ugs, ypart.nys(), nu), _fGstack(&_fgs, ypart.nys(), nu), f(fcont),
+    matA(fcont.get(Symmetry {1}), _uZstack.getStackSizes(), hh.get(Symmetry {1, 0, 0, 0}), ypart)
 {
 }
 
 // KOrderStoch convenience method specializations
 template<>
-ctraits<Storage::unfold>::Tg &
+ctraits<Storage::unfold>::Tg&
 KOrderStoch::g<Storage::unfold>()
 {
   return _ug;
 }
 template<>
-const ctraits<Storage::unfold>::Tg &
+const ctraits<Storage::unfold>::Tg&
 KOrderStoch::g<Storage::unfold>() const
 {
   return _ug;
 }
 template<>
-ctraits<Storage::fold>::Tg &
+ctraits<Storage::fold>::Tg&
 KOrderStoch::g<Storage::fold>()
 {
   return _fg;
 }
 template<>
-const ctraits<Storage::fold>::Tg &
+const ctraits<Storage::fold>::Tg&
 KOrderStoch::g<Storage::fold>() const
 {
   return _fg;
 }
 template<>
-ctraits<Storage::unfold>::Tgs &
+ctraits<Storage::unfold>::Tgs&
 KOrderStoch::gs<Storage::unfold>()
 {
   return _ugs;
 }
 template<>
-const ctraits<Storage::unfold>::Tgs &
+const ctraits<Storage::unfold>::Tgs&
 KOrderStoch::gs<Storage::unfold>() const
 {
   return _ugs;
 }
 template<>
-ctraits<Storage::fold>::Tgs &
+ctraits<Storage::fold>::Tgs&
 KOrderStoch::gs<Storage::fold>()
 {
   return _fgs;
 }
 template<>
-const ctraits<Storage::fold>::Tgs &
+const ctraits<Storage::fold>::Tgs&
 KOrderStoch::gs<Storage::fold>() const
 {
   return _fgs;
 }
 template<>
-const ctraits<Storage::unfold>::Tgss &
+const ctraits<Storage::unfold>::Tgss&
 KOrderStoch::h<Storage::unfold>() const
 {
   return *_uh;
 }
 template<>
-const ctraits<Storage::fold>::Tgss &
+const ctraits<Storage::fold>::Tgss&
 KOrderStoch::h<Storage::fold>() const
 {
   return *_fh;
 }
 template<>
-ctraits<Storage::unfold>::TG &
+ctraits<Storage::unfold>::TG&
 KOrderStoch::G<Storage::unfold>()
 {
   return _uG;
 }
 template<>
-const ctraits<Storage::unfold>::TG &
+const ctraits<Storage::unfold>::TG&
 KOrderStoch::G<Storage::unfold>() const
 {
   return _uG;
 }
 template<>
-ctraits<Storage::fold>::TG &
+ctraits<Storage::fold>::TG&
 KOrderStoch::G<Storage::fold>()
 {
   return _fG;
 }
 template<>
-const ctraits<Storage::fold>::TG &
+const ctraits<Storage::fold>::TG&
 KOrderStoch::G<Storage::fold>() const
 {
   return _fG;
 }
 template<>
-ctraits<Storage::unfold>::TZXstack &
+ctraits<Storage::unfold>::TZXstack&
 KOrderStoch::Zstack<Storage::unfold>()
 {
   return _uZstack;
 }
 template<>
-const ctraits<Storage::unfold>::TZXstack &
+const ctraits<Storage::unfold>::TZXstack&
 KOrderStoch::Zstack<Storage::unfold>() const
 {
   return _uZstack;
 }
 template<>
-ctraits<Storage::fold>::TZXstack &
+ctraits<Storage::fold>::TZXstack&
 KOrderStoch::Zstack<Storage::fold>()
 {
   return _fZstack;
 }
 template<>
-const ctraits<Storage::fold>::TZXstack &
+const ctraits<Storage::fold>::TZXstack&
 KOrderStoch::Zstack<Storage::fold>() const
 {
   return _fZstack;
 }
 template<>
-ctraits<Storage::unfold>::TGXstack &
+ctraits<Storage::unfold>::TGXstack&
 KOrderStoch::Gstack<Storage::unfold>()
 {
   return _uGstack;
 }
 template<>
-const ctraits<Storage::unfold>::TGXstack &
+const ctraits<Storage::unfold>::TGXstack&
 KOrderStoch::Gstack<Storage::unfold>() const
 {
   return _uGstack;
 }
 template<>
-ctraits<Storage::fold>::TGXstack &
+ctraits<Storage::fold>::TGXstack&
 KOrderStoch::Gstack<Storage::fold>()
 {
   return _fGstack;
 }
 template<>
-const ctraits<Storage::fold>::TGXstack &
+const ctraits<Storage::fold>::TGXstack&
 KOrderStoch::Gstack<Storage::fold>() const
 {
   return _fGstack;
diff --git a/mex/sources/libkorder/kord/korder_stoch.hh b/mex/sources/libkorder/kord/korder_stoch.hh
index 6c3a8b205a69f96d172c91e4d53a4492fd9e3728..6fcc46e9fd1438dac248b5df19da9d10702631dc 100644
--- a/mex/sources/libkorder/kord/korder_stoch.hh
+++ b/mex/sources/libkorder/kord/korder_stoch.hh
@@ -40,9 +40,9 @@
 
 #include <memory>
 
-#include "korder.hh"
 #include "faa_di_bruno.hh"
 #include "journal.hh"
+#include "korder.hh"
 #include "pascal_triangle.hh"
 
 /* This class is a container, which has a specialized constructor integrating
@@ -52,8 +52,8 @@ template<Storage t>
 class IntegDerivs : public ctraits<t>::Tgss
 {
 public:
-  IntegDerivs(int r, const IntSequence &nvs, const typename ctraits<t>::Tgss &g,
-              const typename ctraits<t>::Tm &mom, double at_sigma);
+  IntegDerivs(int r, const IntSequence& nvs, const typename ctraits<t>::Tgss& g,
+              const typename ctraits<t>::Tm& mom, double at_sigma);
 };
 
 /* This constructor integrates a rule (namely its g** part) with respect to
@@ -102,17 +102,17 @@ public:
    and this is exactly what the code does.
 */
 template<Storage t>
-IntegDerivs<t>::IntegDerivs(int r, const IntSequence &nvs, const typename ctraits<t>::Tgss &g,
-                            const typename ctraits<t>::Tm &mom, double at_sigma)
-  : ctraits<t>::Tgss(4)
+IntegDerivs<t>::IntegDerivs(int r, const IntSequence& nvs, const typename ctraits<t>::Tgss& g,
+                            const typename ctraits<t>::Tm& mom, double at_sigma) :
+    ctraits<t>::Tgss(4)
 {
   int maxd = g.getMaxDim();
   for (int d = 1; d <= maxd; d++)
     {
       for (int i = 0; i <= d; i++)
         {
-          int p = d-i;
-          Symmetry sym{i, 0, 0, p};
+          int p = d - i;
+          Symmetry sym {i, 0, 0, p};
           auto ten = std::make_unique<typename ctraits<t>::Ttensor>(r, TensorDimens(sym, nvs));
 
           // Calculate derivative h_yⁱσᵖ
@@ -127,20 +127,20 @@ IntegDerivs<t>::IntegDerivs(int r, const IntSequence &nvs, const typename ctrait
           ten->zeros();
           for (int n = 0; n <= p; n++)
             {
-              int k = p-n;
+              int k = p - n;
               int povern = PascalTriangle::noverk(p, n);
               int mfac = 1;
-              for (int m = 0; i+m+n+k <= maxd; m++, mfac *= m)
+              for (int m = 0; i + m + n + k <= maxd; m++, mfac *= m)
                 {
-                  double mult = (pow(at_sigma, m)*povern)/mfac;
-                  Symmetry sym_mn{i, m+n, 0, k};
-                  if (m+n == 0 && g.check(sym_mn))
+                  double mult = (pow(at_sigma, m) * povern) / mfac;
+                  Symmetry sym_mn {i, m + n, 0, k};
+                  if (m + n == 0 && g.check(sym_mn))
                     ten->add(mult, g.get(sym_mn));
-                  if (m+n > 0 && KOrder::is_even(m+n) && g.check(sym_mn))
+                  if (m + n > 0 && KOrder::is_even(m + n) && g.check(sym_mn))
                     {
                       typename ctraits<t>::Ttensor gtmp(g.get(sym_mn));
                       gtmp.mult(mult);
-                      gtmp.contractAndAdd(1, *ten, mom.get(Symmetry{m+n}));
+                      gtmp.contractAndAdd(1, *ten, mom.get(Symmetry {m + n}));
                     }
                 }
             }
@@ -160,9 +160,8 @@ template<Storage t>
 class StochForwardDerivs : public ctraits<t>::Tgss
 {
 public:
-  StochForwardDerivs(const PartitionY &ypart, int nu,
-                     const typename ctraits<t>::Tgss &g, const typename ctraits<t>::Tm &m,
-                     const Vector &ydelta, double sdelta,
+  StochForwardDerivs(const PartitionY& ypart, int nu, const typename ctraits<t>::Tgss& g,
+                     const typename ctraits<t>::Tm& m, const Vector& ydelta, double sdelta,
                      double at_sigma);
 };
 
@@ -181,12 +180,11 @@ public:
    — Recover general symmetry tensors from the (full symmetric) polynomial
 */
 template<Storage t>
-StochForwardDerivs<t>::StochForwardDerivs(const PartitionY &ypart, int nu,
-                                          const typename ctraits<t>::Tgss &g,
-                                          const typename ctraits<t>::Tm &m,
-                                          const Vector &ydelta, double sdelta,
-                                          double at_sigma)
-  : ctraits<t>::Tgss(4)
+StochForwardDerivs<t>::StochForwardDerivs(const PartitionY& ypart, int nu,
+                                          const typename ctraits<t>::Tgss& g,
+                                          const typename ctraits<t>::Tm& m, const Vector& ydelta,
+                                          double sdelta, double at_sigma) :
+    ctraits<t>::Tgss(4)
 {
   int maxd = g.getMaxDim();
   int r = ypart.nyss();
@@ -196,22 +194,21 @@ StochForwardDerivs<t>::StochForwardDerivs(const PartitionY &ypart, int nu,
      the tensors has zero dimensions for shocks, this is because we need to
                                     ⎡y*⎤
      make easily stacks of the form ⎣σ ⎦ in the next step. */
-  IntSequence nvs{ypart.nys(), 0, 0, 1};
+  IntSequence nvs {ypart.nys(), 0, 0, 1};
   IntegDerivs<t> g_int(r, nvs, g, m, at_sigma);
 
   // Make ‘g_int_sym’ be full symmetric polynomial from ‘g_int’
   /* Here we just form a polynomial whose unique variable corresponds to
      ⎡y*⎤
      ⎣σ ⎦ stack. */
-  typename ctraits<t>::Tpol g_int_sym(r, ypart.nys()+1);
+  typename ctraits<t>::Tpol g_int_sym(r, ypart.nys() + 1);
   for (int d = 1; d <= maxd; d++)
     {
-      auto ten = std::make_unique<typename ctraits<t>::Ttensym>(r, ypart.nys()+1, d);
+      auto ten = std::make_unique<typename ctraits<t>::Ttensym>(r, ypart.nys() + 1, d);
       ten->zeros();
       for (int i = 0; i <= d; i++)
-        if (int k {d-i};
-            g_int.check(Symmetry{i, 0, 0, k}))
-          ten->addSubTensor(g_int.get(Symmetry{i, 0, 0, k}));
+        if (int k {d - i}; g_int.check(Symmetry {i, 0, 0, k}))
+          ten->addSubTensor(g_int.get(Symmetry {i, 0, 0, k}));
       g_int_sym.insert(std::move(ten));
     }
 
@@ -220,15 +217,15 @@ StochForwardDerivs<t>::StochForwardDerivs(const PartitionY &ypart, int nu,
      was centralized about (ỹ,σ~). This is done by derivating and evaluating
      the derivated polynomial at (ȳ−ỹ,σ¯-σ~). The stack of this vector is
      ‘delta’ in the code. */
-  Vector delta(ypart.nys()+1);
+  Vector delta(ypart.nys() + 1);
   Vector dy(delta, 0, ypart.nys());
   ConstVector dy_in(ydelta, ypart.nstat, ypart.nys());
   dy = dy_in;
   delta[ypart.nys()] = sdelta;
-  typename ctraits<t>::Tpol g_int_cent(r, ypart.nys()+1);
+  typename ctraits<t>::Tpol g_int_cent(r, ypart.nys() + 1);
   for (int d = 1; d <= maxd; d++)
     {
-      g_int_sym.derivative(d-1);
+      g_int_sym.derivative(d - 1);
       auto der = g_int_sym.evalPartially(d, delta);
       g_int_cent.insert(std::move(der));
     }
@@ -236,20 +233,19 @@ StochForwardDerivs<t>::StochForwardDerivs(const PartitionY &ypart, int nu,
   // Pull out general symmetry tensors from ‘g_int_cent’
   /* Here we only recover the general symmetry derivatives from the full
      symmetric polynomial. Note that the derivative get the true ‘nvs’. */
-  IntSequence ss{ypart.nys(), 0, 0, 1};
-  IntSequence pp{0, 1, 2, 3};
+  IntSequence ss {ypart.nys(), 0, 0, 1};
+  IntSequence pp {0, 1, 2, 3};
   IntSequence true_nvs(nvs);
   true_nvs[1] = nu;
   true_nvs[2] = nu;
   for (int d = 1; d <= maxd; d++)
-    if (g_int_cent.check(Symmetry{d}))
+    if (g_int_cent.check(Symmetry {d}))
       for (int i = 0; i <= d; i++)
         {
-          Symmetry sym{i, 0, 0, d-i};
+          Symmetry sym {i, 0, 0, d - i};
           IntSequence coor(pp.unfold(sym));
-          auto ten = std::make_unique<typename ctraits<t>::Ttensor>(g_int_cent.get(Symmetry{d}),
-                                                                    ss, coor,
-                                                                    TensorDimens(sym, true_nvs));
+          auto ten = std::make_unique<typename ctraits<t>::Ttensor>(
+              g_int_cent.get(Symmetry {d}), ss, coor, TensorDimens(sym, true_nvs));
           this->insert(std::move(ten));
         }
 }
@@ -265,11 +261,10 @@ public:
   using _Stype = StackContainerInterface<_Ttype>;
   using _Ctype = typename StackContainer<_Ttype>::_Ctype;
   using itype = typename StackContainer<_Ttype>::itype;
-  GXContainer(const _Ctype *gs, int ngs, int nu)
-    : GContainer<_Ttype>(gs, ngs, nu)
+  GXContainer(const _Ctype* gs, int ngs, int nu) : GContainer<_Ttype>(gs, ngs, nu)
   {
   }
-  itype getType(int i, const Symmetry &s) const override;
+  itype getType(int i, const Symmetry& s) const override;
 };
 
 /* This routine corresponds to this stack:
@@ -280,7 +275,7 @@ public:
 */
 template<class _Ttype>
 typename GXContainer<_Ttype>::itype
-GXContainer<_Ttype>::getType(int i, const Symmetry &s) const
+GXContainer<_Ttype>::getType(int i, const Symmetry& s) const
 {
   if (i == 0)
     {
@@ -295,7 +290,7 @@ GXContainer<_Ttype>::getType(int i, const Symmetry &s) const
     return itype::zero;
   if (i == 3)
     {
-      if (s == Symmetry{0, 0, 0, 1})
+      if (s == Symmetry {0, 0, 0, 1})
         return itype::unit;
       else
         return itype::zero;
@@ -315,11 +310,11 @@ public:
   using _Stype = StackContainerInterface<_Ttype>;
   using _Ctype = typename StackContainer<_Ttype>::_Ctype;
   using itype = typename StackContainer<_Ttype>::itype;
-  ZXContainer(const _Ctype *gss, int ngss, const _Ctype *g, int ng, int ny, int nu)
-    : ZContainer<_Ttype>(gss, ngss, g, ng, ny, nu)
+  ZXContainer(const _Ctype* gss, int ngss, const _Ctype* g, int ng, int ny, int nu) :
+      ZContainer<_Ttype>(gss, ngss, g, ng, ny, nu)
   {
   }
-  itype getType(int i, const Symmetry &s) const override;
+  itype getType(int i, const Symmetry& s) const override;
 };
 
 /* This getType() method corresponds to this stack:
@@ -330,7 +325,7 @@ public:
 */
 template<class _Ttype>
 typename ZXContainer<_Ttype>::itype
-ZXContainer<_Ttype>::getType(int i, const Symmetry &s) const
+ZXContainer<_Ttype>::getType(int i, const Symmetry& s) const
 {
   if (i == 0)
     {
@@ -348,14 +343,14 @@ ZXContainer<_Ttype>::getType(int i, const Symmetry &s) const
     }
   if (i == 2)
     {
-      if (s == Symmetry{1, 0, 0, 0})
+      if (s == Symmetry {1, 0, 0, 0})
         return itype::unit;
       else
         return itype::zero;
     }
   if (i == 3)
     {
-      if (s == Symmetry{0, 1, 0, 0})
+      if (s == Symmetry {0, 1, 0, 0})
         return itype::unit;
       else
         return itype::zero;
@@ -368,8 +363,7 @@ class UnfoldedGXContainer : public GXContainer<UGSTensor>, public UnfoldedStackC
 {
 public:
   using _Ctype = TensorContainer<UGSTensor>;
-  UnfoldedGXContainer(const _Ctype *gs, int ngs, int nu)
-    : GXContainer<UGSTensor>(gs, ngs, nu)
+  UnfoldedGXContainer(const _Ctype* gs, int ngs, int nu) : GXContainer<UGSTensor>(gs, ngs, nu)
   {
   }
 };
@@ -378,8 +372,7 @@ class FoldedGXContainer : public GXContainer<FGSTensor>, public FoldedStackConta
 {
 public:
   using _Ctype = TensorContainer<FGSTensor>;
-  FoldedGXContainer(const _Ctype *gs, int ngs, int nu)
-    : GXContainer<FGSTensor>(gs, ngs, nu)
+  FoldedGXContainer(const _Ctype* gs, int ngs, int nu) : GXContainer<FGSTensor>(gs, ngs, nu)
   {
   }
 };
@@ -388,8 +381,8 @@ class UnfoldedZXContainer : public ZXContainer<UGSTensor>, public UnfoldedStackC
 {
 public:
   using _Ctype = TensorContainer<UGSTensor>;
-  UnfoldedZXContainer(const _Ctype *gss, int ngss, const _Ctype *g, int ng, int ny, int nu)
-    : ZXContainer<UGSTensor>(gss, ngss, g, ng, ny, nu)
+  UnfoldedZXContainer(const _Ctype* gss, int ngss, const _Ctype* g, int ng, int ny, int nu) :
+      ZXContainer<UGSTensor>(gss, ngss, g, ng, ny, nu)
   {
   }
 };
@@ -398,8 +391,8 @@ class FoldedZXContainer : public ZXContainer<FGSTensor>, public FoldedStackConta
 {
 public:
   using _Ctype = TensorContainer<FGSTensor>;
-  FoldedZXContainer(const _Ctype *gss, int ngss, const _Ctype *g, int ng, int ny, int nu)
-    : ZXContainer<FGSTensor>(gss, ngss, g, ng, ny, nu)
+  FoldedZXContainer(const _Ctype* gss, int ngss, const _Ctype* g, int ng, int ny, int nu) :
+      ZXContainer<FGSTensor>(gss, ngss, g, ng, ny, nu)
   {
   }
 };
@@ -415,8 +408,8 @@ public:
 class MatrixAA : public PLUMatrix
 {
 public:
-  MatrixAA(const FSSparseTensor &f, const IntSequence &ss,
-           const TwoDMatrix &gyss, const PartitionY &ypart);
+  MatrixAA(const FSSparseTensor& f, const IntSequence& ss, const TwoDMatrix& gyss,
+           const PartitionY& ypart);
 };
 
 /* This class calculates derivatives of g given implicitly by
@@ -436,77 +429,79 @@ class KOrderStoch
 protected:
   IntSequence nvs;
   PartitionY ypart;
-  Journal &journal;
+  Journal& journal;
   UGSContainer _ug;
   FGSContainer _fg;
   UGSContainer _ugs;
   FGSContainer _fgs;
   UGSContainer _uG;
   FGSContainer _fG;
-  const UGSContainer *_uh;
-  const FGSContainer *_fh;
+  const UGSContainer* _uh;
+  const FGSContainer* _fh;
   UnfoldedZXContainer _uZstack;
   FoldedZXContainer _fZstack;
   UnfoldedGXContainer _uGstack;
   FoldedGXContainer _fGstack;
-  const TensorContainer<FSSparseTensor> &f;
+  const TensorContainer<FSSparseTensor>& f;
   MatrixAA matA;
+
 public:
-  KOrderStoch(const PartitionY &ypart, int nu, const TensorContainer<FSSparseTensor> &fcont,
-              const FGSContainer &hh, Journal &jr);
-  KOrderStoch(const PartitionY &ypart, int nu, const TensorContainer<FSSparseTensor> &fcont,
-              const UGSContainer &hh, Journal &jr);
+  KOrderStoch(const PartitionY& ypart, int nu, const TensorContainer<FSSparseTensor>& fcont,
+              const FGSContainer& hh, Journal& jr);
+  KOrderStoch(const PartitionY& ypart, int nu, const TensorContainer<FSSparseTensor>& fcont,
+              const UGSContainer& hh, Journal& jr);
   template<Storage t>
   void performStep(int order);
-  const FGSContainer &
+  const FGSContainer&
   getFoldDers() const
   {
     return _fg;
   }
-  const UGSContainer &
+  const UGSContainer&
   getUnfoldDers() const
   {
     return _ug;
   }
-  const FGSContainer &
+  const FGSContainer&
   getFoldDersS() const
   {
     return _fgs;
   }
+
 protected:
   template<Storage t>
-  std::unique_ptr<typename ctraits<t>::Ttensor> faaDiBrunoZ(const Symmetry &sym) const;
+  std::unique_ptr<typename ctraits<t>::Ttensor> faaDiBrunoZ(const Symmetry& sym) const;
   template<Storage t>
-  std::unique_ptr<typename ctraits<t>::Ttensor> faaDiBrunoG(const Symmetry &sym) const;
+  std::unique_ptr<typename ctraits<t>::Ttensor> faaDiBrunoG(const Symmetry& sym) const;
 
   // Convenience access methods
   template<Storage t>
-  typename ctraits<t>::Tg &g();
+  typename ctraits<t>::Tg& g();
   template<Storage t>
-  const typename ctraits<t>::Tg &g() const;
+  const typename ctraits<t>::Tg& g() const;
 
   template<Storage t>
-  typename ctraits<t>::Tgs &gs();
+  typename ctraits<t>::Tgs& gs();
   template<Storage t>
-  const typename ctraits<t>::Tgs &gs() const;
+  const typename ctraits<t>::Tgs& gs() const;
 
   template<Storage t>
-  const typename ctraits<t>::Tgss &h() const;
+  const typename ctraits<t>::Tgss& h() const;
 
   template<Storage t>
-  typename ctraits<t>::TG &G();
+  typename ctraits<t>::TG& G();
   template<Storage t>
-  const typename ctraits<t>::TG &G() const;
+  const typename ctraits<t>::TG& G() const;
 
   template<Storage t>
-  typename ctraits<t>::TZXstack &Zstack();
+  typename ctraits<t>::TZXstack& Zstack();
   template<Storage t>
-  const typename ctraits<t>::TZXstack &Zstack() const;
+  const typename ctraits<t>::TZXstack& Zstack() const;
 
   template<Storage t>
-  typename ctraits<t>::TGXstack &Gstack();
+  typename ctraits<t>::TGXstack& Gstack();
   template<Storage t>
-  const typename ctraits<t>::TGXstack &Gstack() const;
+  const typename ctraits<t>::TGXstack& Gstack() const;
 };
 
 /* This calculates a derivative of f(G(y,u,σ),g(y,u,σ),y,u) of a given
@@ -514,7 +509,7 @@ protected:
 
 template<Storage t>
 std::unique_ptr<typename ctraits<t>::Ttensor>
-KOrderStoch::faaDiBrunoZ(const Symmetry &sym) const
+KOrderStoch::faaDiBrunoZ(const Symmetry& sym) const
 {
   JournalRecordPair pa(journal);
   pa << "Faà Di Bruno ZX container for " << sym << endrec;
@@ -529,7 +524,7 @@ KOrderStoch::faaDiBrunoZ(const Symmetry &sym) const
 
 template<Storage t>
 std::unique_ptr<typename ctraits<t>::Ttensor>
-KOrderStoch::faaDiBrunoG(const Symmetry &sym) const
+KOrderStoch::faaDiBrunoG(const Symmetry& sym) const
 {
   JournalRecordPair pa(journal);
   pa << "Faà Di Bruno GX container for " << sym << endrec;
@@ -555,9 +550,9 @@ void
 KOrderStoch::performStep(int order)
 {
   int maxd = g<t>().getMaxDim();
-  KORD_RAISE_IF(order-1 != maxd && (order != 1 || maxd != -1),
+  KORD_RAISE_IF(order - 1 != maxd && (order != 1 || maxd != -1),
                 "Wrong order for KOrderStoch::performStep");
-  for (auto &si : SymmetrySet(order, 4))
+  for (auto& si : SymmetrySet(order, 4))
     if (si[2] == 0)
       {
         JournalRecordPair pa(journal);
@@ -572,8 +567,8 @@ KOrderStoch::performStep(int order)
         g_sym->mult(-1.0);
         matA.multInv(*g_sym);
         g<t>().insert(std::move(g_sym));
-        gs<t>().insert(std::make_unique<typename ctraits<t>::Ttensor>(ypart.nstat, ypart.nys(),
-                                                                      *g_sym_ptr));
+        gs<t>().insert(
+            std::make_unique<typename ctraits<t>::Ttensor>(ypart.nstat, ypart.nys(), *g_sym_ptr));
 
         Gstack<t>().multAndAdd(1, h<t>(), *G_sym_ptr);
       }
diff --git a/mex/sources/libkorder/kord/tests/tests.cc b/mex/sources/libkorder/kord/tests/tests.cc
index 15ce932a3f5ad021ea4a80e554d0db339096a1f4..8cbeed2ba7f92c9bc355407cc08092e11447ad01 100644
--- a/mex/sources/libkorder/kord/tests/tests.cc
+++ b/mex/sources/libkorder/kord/tests/tests.cc
@@ -19,16 +19,16 @@
  */
 
 #include <chrono>
+#include <iomanip>
+#include <iostream>
+#include <memory>
 #include <random>
 #include <string>
 #include <utility>
-#include <iostream>
-#include <iomanip>
 #include <vector>
-#include <memory>
 
-#include "korder.hh"
 #include "SylvException.hh"
+#include "korder.hh"
 
 struct Rand
 {
@@ -44,32 +44,32 @@ std::mt19937 Rand::mtgen;
 std::uniform_real_distribution<> Rand::dis;
 
 ConstTwoDMatrix
-make_matrix(int rows, int cols, const double *p)
+make_matrix(int rows, int cols, const double* p)
 {
-  return ConstTwoDMatrix{rows, cols, ConstVector{p, rows*cols}};
+  return ConstTwoDMatrix {rows, cols, ConstVector {p, rows * cols}};
 }
 
 void
 Rand::init(int n1, int n2, int n3, int n4, int n5)
 {
   decltype(mtgen)::result_type seed = n1;
-  seed = 256*seed+n2;
-  seed = 256*seed+n3;
-  seed = 256*seed+n4;
-  seed = 256*seed+n5;
+  seed = 256 * seed + n2;
+  seed = 256 * seed + n3;
+  seed = 256 * seed + n4;
+  seed = 256 * seed + n5;
   mtgen.seed(seed);
 }
 
 double
 Rand::get(double m)
 {
-  return 2*m*(dis(mtgen)-0.5);
+  return 2 * m * (dis(mtgen) - 0.5);
 }
 
 int
 Rand::get(int m)
 {
-  return static_cast<int>(get(0.9999*m));
+  return static_cast<int>(get(0.9999 * m));
 }
 
 bool
@@ -80,15 +80,13 @@ Rand::discrete(double prob)
 
 struct SparseGenerator
 {
-  static std::unique_ptr<FSSparseTensor> makeTensor(int dim, int nv, int r,
-                                                    double fill, double m);
-  static void fillContainer(TensorContainer<FSSparseTensor> &c,
-                            int maxdim, int nv, int r, double m);
+  static std::unique_ptr<FSSparseTensor> makeTensor(int dim, int nv, int r, double fill, double m);
+  static void fillContainer(TensorContainer<FSSparseTensor>& c, int maxdim, int nv, int r,
+                            double m);
 };
 
 std::unique_ptr<FSSparseTensor>
-SparseGenerator::makeTensor(int dim, int nv, int r,
-                            double fill, double m)
+SparseGenerator::makeTensor(int dim, int nv, int r, double fill, double m)
 {
   auto res = std::make_unique<FSSparseTensor>(dim, nv, r);
   FFSTensor dummy(0, nv, dim);
@@ -103,11 +101,10 @@ SparseGenerator::makeTensor(int dim, int nv, int r,
 }
 
 void
-SparseGenerator::fillContainer(TensorContainer<FSSparseTensor> &c,
-                               int maxdim, int nv, int r,
+SparseGenerator::fillContainer(TensorContainer<FSSparseTensor>& c, int maxdim, int nv, int r,
                                double m)
 {
-  Rand::init(maxdim, nv, r, static_cast<int>(5*m), 0);
+  Rand::init(maxdim, nv, r, static_cast<int>(5 * m), 0);
   double fill = 0.5;
   for (int d = 1; d <= maxdim; d++)
     {
@@ -116,166 +113,159 @@ SparseGenerator::fillContainer(TensorContainer<FSSparseTensor> &c,
     }
 }
 
-const double vdata[] =
-  { // 3x3
-   0.1307870268, 0.1241940078, 0.1356703123,
-   0.1241940078, 0.1986920419, 0.2010160581,
-   0.1356703123, 0.2010160581, 0.2160336975
-  };
-
-const double gy_data[] =
-  { // 8x4
-   0.3985178619, -0.5688233582, 0.9572900437, -0.6606847776, 0.1453004017,
-   0.3025310675, -0.8627437750, -0.6903410191, 0.4751910580, -0.7270018589,
-   -0.0939612498, -0.1463831989, 0.6742110220, 0.6046671043, 0.5215893126,
-   -1.0412969986, -0.3524898417, -1.0986703430, 0.8006531522, 0.8879776376,
-   -0.1037608317, -0.5587378073, -0.1010366945, 0.9462411248, -0.2439199881,
-   1.3420621236, -0.7820285935, 0.3205293447, 0.3606124791, 0.2975422208,
-   -0.5452861965, 1.6320340279
-  };
-
-const double gu_data[] =
-  { // just some numbers, no structure
-   1.8415286914, -0.2638743845, 1.7690713274, 0.9668585956, 0.2303143646,
-   -0.2229624279, -0.4381991822, 1.0082401405, -0.3186555860, -0.0624691529,
-   -0.5189085756, 1.4269672156, 0.1163282969, 1.4020183445, -0.0952660426,
-   0.2099097124, 0.6912400502, -0.5180935114, 0.5288316624, 0.2188053448,
-   0.5715516767, 0.7813893410, -0.6385073106, 0.8335131513, 0.3605202168,
-   -1.1167944865, -1.2263750934, 0.6113636081, 0.6964915482, -0.6451217688,
-   0.4062810500, -2.0552251116, -1.6383406284, 0.0198915095, 0.0111014458,
-   -1.2421792262, -1.0724161722, -0.4276904972, 0.1801494950, -2.0716473264
-  };
-
-const double vdata2[] =
-  { // 10×10 positive definite
-   0.79666, -0.15536, 0.05667, -0.21026, 0.20262, 0.28505, 0.60341, -0.09703, 0.32363, 0.13299,
-   -0.15536, 0.64380, -0.01131, 0.00980, 0.03755, 0.43791, 0.21784, -0.31755, -0.55911, -0.29655,
-   0.05667, -0.01131, 0.56165, -0.34357, -0.40584, 0.20990, 0.28348, 0.20398, -0.19856, 0.35820,
-   -0.21026, 0.00980, -0.34357, 0.56147, 0.10972, -0.34146, -0.49906, -0.19685, 0.21088, -0.31560,
-   0.20262, 0.03755, -0.40584, 0.10972, 0.72278, 0.02155, 0.04089, -0.19696, 0.03446, -0.12919,
-   0.28505, 0.43791, 0.20990, -0.34146, 0.02155, 0.75867, 0.77699, -0.31125, -0.55141, -0.02155,
-   0.60341, 0.21784, 0.28348, -0.49906, 0.04089, 0.77699, 1.34553, -0.18613, -0.25811, -0.19016,
-   -0.09703, -0.31755, 0.20398, -0.19685, -0.19696, -0.31125, -0.18613, 0.59470, 0.08386, 0.41750,
-   0.32363, -0.55911, -0.19856, 0.21088, 0.03446, -0.55141, -0.25811, 0.08386, 0.98917, -0.12992,
-   0.13299, -0.29655, 0.35820, -0.31560, -0.12919, -0.02155, -0.19016, 0.41750, -0.12992, 0.89608
-  };
-
-const double gy_data2[] =
-  { // 600 items make gy 30×20, whose gy(6:25,:) has spectrum within unit
-   0.39414, -0.29766, 0.08948, -0.19204, -0.00750, 0.21159, 0.05494, 0.06225, 0.01771, 0.21913,
-   -0.01373, 0.20086, -0.06086, -0.10955, 0.14424, -0.08390, 0.03948, -0.14713, 0.11674, 0.05091,
-   0.24039, 0.28307, -0.11835, 0.13030, 0.11682, -0.27444, -0.19311, -0.16654, 0.12867, 0.25116,
-   -0.19781, 0.45242, -0.15862, 0.24428, -0.11966, 0.11483, -0.32279, 0.29727, 0.20934, -0.18190,
-   -0.15080, -0.09477, -0.30551, -0.02672, -0.26919, 0.11165, -0.06390, 0.03449, -0.26622, 0.22197,
-   0.45141, -0.41683, 0.09760, 0.31094, -0.01652, 0.05809, -0.04514, -0.05645, 0.00554, 0.47980,
-   0.11726, 0.42459, -0.13136, -0.30902, -0.14648, 0.11455, 0.02947, -0.03835, -0.04044, 0.03559,
-   -0.26575, -0.01783, 0.31243, -0.14412, -0.13218, -0.05080, 0.18576, 0.13840, -0.05560, 0.35530,
-   -0.25573, -0.11560, 0.15187, -0.18431, 0.08193, -0.32278, 0.17560, -0.05529, -0.10020, -0.23088,
-   -0.20979, -0.49245, 0.09915, -0.16909, -0.03443, 0.19497, 0.18473, 0.25662, 0.29605, -0.20531,
-   -0.39244, -0.43369, 0.05588, 0.24823, -0.14236, -0.08311, 0.16371, -0.19975, 0.30605, -0.17087,
-   -0.01270, 0.00123, -0.22426, -0.13810, 0.05079, 0.06971, 0.01922, -0.09952, -0.23177, -0.41962,
-   -0.41991, 0.41430, -0.04247, -0.13706, -0.12048, -0.28906, -0.22813, -0.25057, -0.18579, -0.20642,
-   -0.47976, 0.25490, -0.05138, -0.30794, 0.31651, 0.02034, 0.12954, -0.20110, 0.13336, -0.40775,
-   -0.30195, -0.13704, 0.12396, 0.28152, 0.02986, 0.27669, 0.24623, 0.08635, -0.11956, -0.02949,
-   0.37401, 0.20838, 0.24801, -0.26872, 0.11195, 0.00315, -0.19069, 0.12839, -0.23036, -0.48228,
-   0.08434, -0.39872, -0.28896, -0.28754, 0.24668, 0.23285, 0.25437, 0.10456, -0.14124, 0.20483,
-   -0.19117, -0.33836, -0.24875, 0.08207, -0.03930, 0.20364, 0.15384, -0.15270, 0.24372, -0.11199,
-   -0.46591, 0.30319, 0.05745, 0.09084, 0.06058, 0.31884, 0.05071, -0.28899, -0.30793, -0.03566,
-   0.02286, 0.28178, 0.00736, -0.31378, -0.18144, -0.22346, -0.27239, 0.31043, -0.26228, 0.22181,
-   -0.15096, -0.36953, -0.06032, 0.21496, 0.29545, -0.13112, 0.16420, -0.07573, -0.43111, -0.43057,
-   0.26716, -0.31209, -0.05866, -0.29101, -0.27437, -0.18727, 0.28732, -0.19014, 0.08837, 0.30405,
-   0.06103, -0.35612, 0.00173, 0.25134, -0.08987, -0.22766, -0.03254, -0.18662, -0.08491, 0.49401,
-   -0.12145, -0.02961, -0.03668, -0.30043, -0.08555, 0.01701, -0.12544, 0.10969, -0.48202, 0.07245,
-   0.20673, 0.11408, 0.04343, -0.01815, -0.31594, -0.23632, -0.06258, -0.27474, 0.12180, 0.16613,
-   -0.37931, 0.30219, 0.15765, 0.25489, 0.17529, -0.17020, -0.30060, 0.22058, -0.02450, -0.42143,
-   0.49642, 0.46899, -0.28552, -0.22549, -0.01333, 0.21567, 0.22251, 0.21639, -0.19194, -0.19140,
-   -0.24106, 0.10952, -0.11019, 0.29763, -0.02039, -0.25748, 0.23169, 0.01357, 0.09802, -0.19022,
-   0.37604, -0.40777, 0.18131, -0.10258, 0.29573, -0.31773, 0.09069, -0.02198, -0.26594, 0.48302,
-   -0.10041, 0.20210, -0.05609, -0.01169, -0.17339, 0.17862, -0.22502, 0.29009, -0.45160, 0.19771,
-   0.27634, 0.31695, -0.09993, 0.17167, 0.12394, 0.28088, -0.12502, -0.16967, -0.06296, -0.17036,
-   0.27320, 0.01595, 0.16955, 0.30146, -0.15173, -0.29807, 0.08178, -0.06811, 0.21655, 0.26348,
-   0.06316, 0.45661, -0.29756, -0.05742, -0.14715, -0.03037, -0.16656, -0.08768, 0.38078, 0.40679,
-   -0.32779, -0.09106, 0.16107, -0.07301, 0.07700, -0.22694, -0.15692, -0.02548, 0.38749, -0.12203,
-   -0.02980, -0.22067, 0.00680, -0.23058, -0.29112, 0.23032, -0.16026, 0.23392, -0.09990, 0.03628,
-   -0.42592, -0.33474, -0.09499, -0.17442, -0.20110, 0.24618, -0.06418, -0.06715, 0.40754, 0.29377,
-   0.29543, -0.16832, -0.08468, 0.06491, -0.01410, 0.19988, 0.24950, 0.14626, -0.27851, 0.06079,
-   0.48134, -0.13475, 0.25398, 0.11738, 0.23369, -0.00661, -0.16811, -0.04557, -0.12030, -0.39527,
-   -0.35760, 0.01840, -0.15941, 0.03290, 0.09988, -0.08307, 0.06644, -0.24637, 0.34112, -0.08026,
-   0.00951, 0.27656, 0.16247, 0.28217, 0.17198, -0.16389, -0.03835, -0.02675, -0.08032, -0.21045,
-   -0.38946, 0.23207, 0.10987, -0.31674, -0.28653, -0.27430, -0.29109, -0.00648, 0.38431, -0.38478,
-   -0.41195, -0.19364, -0.20977, -0.05524, 0.05558, -0.20109, 0.11803, -0.19884, 0.43318, -0.39255,
-   0.26612, -0.21771, 0.12471, 0.12856, -0.15104, -0.11676, 0.17582, -0.25330, 0.00298, -0.31712,
-   0.21532, -0.20319, 0.14507, -0.04588, -0.22995, -0.06470, 0.18849, -0.13444, 0.37107, 0.07387,
-   -0.14008, 0.09896, 0.13727, -0.28417, -0.09461, -0.18703, 0.04080, 0.02343, -0.49988, 0.17993,
-   0.23189, -0.30581, -0.18334, -0.09667, -0.27699, -0.05998, 0.09118, -0.32453, 0.46251, 0.41500,
-   -0.45314, -0.00544, 0.08529, 0.29099, -0.00937, -0.31650, 0.26163, 0.14506, 0.37498, -0.16454,
-   0.35215, 0.31642, -0.09161, -0.31452, -0.04792, -0.04677, -0.19523, 0.27998, 0.05491, 0.44461,
-   -0.01258, -0.27887, 0.18361, -0.04539, -0.02977, 0.30821, 0.29454, -0.17932, 0.16193, 0.23934,
-   0.47923, 0.25373, 0.23258, 0.31484, -0.17958, -0.01136, 0.17681, 0.12869, 0.03235, 0.43762,
-   0.13734, -0.09433, -0.03735, 0.17949, 0.14122, -0.17814, 0.06359, 0.16044, 0.12249, -0.22314,
-   0.40775, 0.05147, 0.12389, 0.04290, -0.01642, 0.00082, -0.18056, 0.02875, 0.32690, 0.17712,
-   0.34001, -0.21581, -0.01086, -0.18180, 0.17480, -0.17774, -0.07503, 0.28438, -0.19747, 0.29595,
-   -0.28002, -0.02073, -0.16522, -0.18234, -0.20565, 0.29620, 0.07502, 0.01429, -0.31418, 0.43693,
-   -0.12212, 0.11178, -0.28503, 0.04683, 0.00072, 0.05566, 0.18857, 0.26101, -0.38891, -0.21216,
-   -0.21850, -0.15147, -0.30749, -0.23762, 0.14984, 0.03535, -0.02862, -0.00105, -0.39907, -0.06909,
-   -0.36094, 0.21717, 0.15930, -0.18924, 0.13741, 0.01039, 0.13613, 0.00659, 0.07676, -0.13711,
-   0.24285, -0.07564, -0.28349, -0.15658, 0.03135, -0.30909, -0.22534, 0.17363, -0.19376, 0.26038,
-   0.05546, -0.22607, 0.32420, -0.02552, -0.05400, 0.13388, 0.04643, -0.31535, -0.06181, 0.30237,
-   -0.04680, -0.29441, 0.12231, 0.03960, -0.01188, 0.01406, 0.25402, 0.03315, 0.25026, -0.10922
-  };
-
-const double gu_data2[] =
-  { // raw data 300 items
-   0.26599, 0.41329, 0.31846, 0.92590, 0.43050, 0.17466, 0.02322, 0.72621, 0.37921, 0.70597,
-   0.97098, 0.14023, 0.57619, 0.09938, 0.02281, 0.92341, 0.72654, 0.71000, 0.76687, 0.70182,
-   0.88752, 0.49524, 0.42549, 0.42806, 0.57615, 0.76051, 0.15341, 0.47457, 0.60066, 0.40880,
-   0.20668, 0.41949, 0.97620, 0.94318, 0.71491, 0.56402, 0.23553, 0.94387, 0.78567, 0.06362,
-   0.85252, 0.86262, 0.25190, 0.03274, 0.93216, 0.37971, 0.08797, 0.14596, 0.73871, 0.06574,
-   0.67447, 0.28575, 0.43911, 0.92133, 0.12327, 0.87762, 0.71060, 0.07141, 0.55443, 0.53310,
-   0.91529, 0.25121, 0.07593, 0.94490, 0.28656, 0.82174, 0.68887, 0.67337, 0.99291, 0.03316,
-   0.02849, 0.33891, 0.25594, 0.90071, 0.01248, 0.67871, 0.65953, 0.65369, 0.97574, 0.31578,
-   0.23678, 0.39220, 0.06706, 0.80943, 0.57694, 0.08220, 0.18151, 0.19969, 0.37096, 0.37858,
-   0.70153, 0.46816, 0.76511, 0.02520, 0.39387, 0.25527, 0.39050, 0.60141, 0.30322, 0.46195,
-   0.12025, 0.33616, 0.04174, 0.00196, 0.68886, 0.74445, 0.15869, 0.18994, 0.95195, 0.62874,
-   0.82874, 0.53369, 0.34383, 0.50752, 0.97023, 0.22695, 0.62407, 0.25840, 0.71279, 0.28785,
-   0.31611, 0.20391, 0.19702, 0.40760, 0.85158, 0.68369, 0.63760, 0.09879, 0.11924, 0.32920,
-   0.53052, 0.15900, 0.21229, 0.84080, 0.33933, 0.93651, 0.42705, 0.06199, 0.50092, 0.47192,
-   0.57152, 0.01818, 0.31404, 0.50173, 0.87725, 0.50530, 0.10717, 0.04035, 0.32901, 0.33538,
-   0.04780, 0.40984, 0.78216, 0.91288, 0.11314, 0.25248, 0.23823, 0.74001, 0.48089, 0.55531,
-   0.82486, 0.01058, 0.05409, 0.44357, 0.52641, 0.68188, 0.94629, 0.61627, 0.33037, 0.11961,
-   0.57988, 0.19653, 0.91902, 0.59838, 0.52974, 0.28364, 0.45767, 0.65836, 0.63045, 0.76140,
-   0.27918, 0.27256, 0.46035, 0.77418, 0.92918, 0.14095, 0.89645, 0.25146, 0.21172, 0.47910,
-   0.95451, 0.34377, 0.29927, 0.79220, 0.97654, 0.67591, 0.44385, 0.38434, 0.44860, 0.28170,
-   0.90712, 0.20337, 0.00292, 0.55046, 0.62255, 0.45127, 0.80896, 0.43965, 0.59145, 0.23801,
-   0.33601, 0.30119, 0.89935, 0.40850, 0.98226, 0.75430, 0.68318, 0.65407, 0.68067, 0.32942,
-   0.11756, 0.27626, 0.83879, 0.72174, 0.75430, 0.13702, 0.03402, 0.58781, 0.07393, 0.23067,
-   0.92537, 0.29445, 0.43437, 0.47685, 0.54548, 0.66082, 0.23805, 0.60208, 0.94337, 0.21363,
-   0.72637, 0.57181, 0.77679, 0.63931, 0.72860, 0.38901, 0.94920, 0.04535, 0.12863, 0.40550,
-   0.90095, 0.21418, 0.13953, 0.99639, 0.02526, 0.70018, 0.21828, 0.20294, 0.20191, 0.30954,
-   0.39490, 0.68955, 0.11506, 0.15748, 0.40252, 0.91680, 0.61547, 0.78443, 0.19693, 0.67630,
-   0.56552, 0.58556, 0.53554, 0.53507, 0.09831, 0.21229, 0.83135, 0.26375, 0.89287, 0.97069,
-   0.70615, 0.42041, 0.43117, 0.21291, 0.26086, 0.26978, 0.77340, 0.43833, 0.46179, 0.54418,
-   0.67878, 0.42776, 0.61454, 0.55915, 0.36363, 0.31999, 0.42442, 0.86649, 0.62513, 0.02047
-  };
+const double vdata[] = { // 3x3
+    0.1307870268, 0.1241940078, 0.1356703123, 0.1241940078, 0.1986920419,
+    0.2010160581, 0.1356703123, 0.2010160581, 0.2160336975};
+
+const double gy_data[] = { // 8x4
+    0.3985178619,  -0.5688233582, 0.9572900437,  -0.6606847776, 0.1453004017,  0.3025310675,
+    -0.8627437750, -0.6903410191, 0.4751910580,  -0.7270018589, -0.0939612498, -0.1463831989,
+    0.6742110220,  0.6046671043,  0.5215893126,  -1.0412969986, -0.3524898417, -1.0986703430,
+    0.8006531522,  0.8879776376,  -0.1037608317, -0.5587378073, -0.1010366945, 0.9462411248,
+    -0.2439199881, 1.3420621236,  -0.7820285935, 0.3205293447,  0.3606124791,  0.2975422208,
+    -0.5452861965, 1.6320340279};
+
+const double gu_data[] = { // just some numbers, no structure
+    1.8415286914,  -0.2638743845, 1.7690713274,  0.9668585956,  0.2303143646,  -0.2229624279,
+    -0.4381991822, 1.0082401405,  -0.3186555860, -0.0624691529, -0.5189085756, 1.4269672156,
+    0.1163282969,  1.4020183445,  -0.0952660426, 0.2099097124,  0.6912400502,  -0.5180935114,
+    0.5288316624,  0.2188053448,  0.5715516767,  0.7813893410,  -0.6385073106, 0.8335131513,
+    0.3605202168,  -1.1167944865, -1.2263750934, 0.6113636081,  0.6964915482,  -0.6451217688,
+    0.4062810500,  -2.0552251116, -1.6383406284, 0.0198915095,  0.0111014458,  -1.2421792262,
+    -1.0724161722, -0.4276904972, 0.1801494950,  -2.0716473264};
+
+const double vdata2[] = { // 10×10 positive definite
+    0.79666,  -0.15536, 0.05667,  -0.21026, 0.20262,  0.28505,  0.60341,  -0.09703, 0.32363,
+    0.13299,  -0.15536, 0.64380,  -0.01131, 0.00980,  0.03755,  0.43791,  0.21784,  -0.31755,
+    -0.55911, -0.29655, 0.05667,  -0.01131, 0.56165,  -0.34357, -0.40584, 0.20990,  0.28348,
+    0.20398,  -0.19856, 0.35820,  -0.21026, 0.00980,  -0.34357, 0.56147,  0.10972,  -0.34146,
+    -0.49906, -0.19685, 0.21088,  -0.31560, 0.20262,  0.03755,  -0.40584, 0.10972,  0.72278,
+    0.02155,  0.04089,  -0.19696, 0.03446,  -0.12919, 0.28505,  0.43791,  0.20990,  -0.34146,
+    0.02155,  0.75867,  0.77699,  -0.31125, -0.55141, -0.02155, 0.60341,  0.21784,  0.28348,
+    -0.49906, 0.04089,  0.77699,  1.34553,  -0.18613, -0.25811, -0.19016, -0.09703, -0.31755,
+    0.20398,  -0.19685, -0.19696, -0.31125, -0.18613, 0.59470,  0.08386,  0.41750,  0.32363,
+    -0.55911, -0.19856, 0.21088,  0.03446,  -0.55141, -0.25811, 0.08386,  0.98917,  -0.12992,
+    0.13299,  -0.29655, 0.35820,  -0.31560, -0.12919, -0.02155, -0.19016, 0.41750,  -0.12992,
+    0.89608};
+
+const double gy_data2[] = { // 600 items make gy 30×20, whose gy(6:25,:) has spectrum within unit
+    0.39414,  -0.29766, 0.08948,  -0.19204, -0.00750, 0.21159,  0.05494,  0.06225,  0.01771,
+    0.21913,  -0.01373, 0.20086,  -0.06086, -0.10955, 0.14424,  -0.08390, 0.03948,  -0.14713,
+    0.11674,  0.05091,  0.24039,  0.28307,  -0.11835, 0.13030,  0.11682,  -0.27444, -0.19311,
+    -0.16654, 0.12867,  0.25116,  -0.19781, 0.45242,  -0.15862, 0.24428,  -0.11966, 0.11483,
+    -0.32279, 0.29727,  0.20934,  -0.18190, -0.15080, -0.09477, -0.30551, -0.02672, -0.26919,
+    0.11165,  -0.06390, 0.03449,  -0.26622, 0.22197,  0.45141,  -0.41683, 0.09760,  0.31094,
+    -0.01652, 0.05809,  -0.04514, -0.05645, 0.00554,  0.47980,  0.11726,  0.42459,  -0.13136,
+    -0.30902, -0.14648, 0.11455,  0.02947,  -0.03835, -0.04044, 0.03559,  -0.26575, -0.01783,
+    0.31243,  -0.14412, -0.13218, -0.05080, 0.18576,  0.13840,  -0.05560, 0.35530,  -0.25573,
+    -0.11560, 0.15187,  -0.18431, 0.08193,  -0.32278, 0.17560,  -0.05529, -0.10020, -0.23088,
+    -0.20979, -0.49245, 0.09915,  -0.16909, -0.03443, 0.19497,  0.18473,  0.25662,  0.29605,
+    -0.20531, -0.39244, -0.43369, 0.05588,  0.24823,  -0.14236, -0.08311, 0.16371,  -0.19975,
+    0.30605,  -0.17087, -0.01270, 0.00123,  -0.22426, -0.13810, 0.05079,  0.06971,  0.01922,
+    -0.09952, -0.23177, -0.41962, -0.41991, 0.41430,  -0.04247, -0.13706, -0.12048, -0.28906,
+    -0.22813, -0.25057, -0.18579, -0.20642, -0.47976, 0.25490,  -0.05138, -0.30794, 0.31651,
+    0.02034,  0.12954,  -0.20110, 0.13336,  -0.40775, -0.30195, -0.13704, 0.12396,  0.28152,
+    0.02986,  0.27669,  0.24623,  0.08635,  -0.11956, -0.02949, 0.37401,  0.20838,  0.24801,
+    -0.26872, 0.11195,  0.00315,  -0.19069, 0.12839,  -0.23036, -0.48228, 0.08434,  -0.39872,
+    -0.28896, -0.28754, 0.24668,  0.23285,  0.25437,  0.10456,  -0.14124, 0.20483,  -0.19117,
+    -0.33836, -0.24875, 0.08207,  -0.03930, 0.20364,  0.15384,  -0.15270, 0.24372,  -0.11199,
+    -0.46591, 0.30319,  0.05745,  0.09084,  0.06058,  0.31884,  0.05071,  -0.28899, -0.30793,
+    -0.03566, 0.02286,  0.28178,  0.00736,  -0.31378, -0.18144, -0.22346, -0.27239, 0.31043,
+    -0.26228, 0.22181,  -0.15096, -0.36953, -0.06032, 0.21496,  0.29545,  -0.13112, 0.16420,
+    -0.07573, -0.43111, -0.43057, 0.26716,  -0.31209, -0.05866, -0.29101, -0.27437, -0.18727,
+    0.28732,  -0.19014, 0.08837,  0.30405,  0.06103,  -0.35612, 0.00173,  0.25134,  -0.08987,
+    -0.22766, -0.03254, -0.18662, -0.08491, 0.49401,  -0.12145, -0.02961, -0.03668, -0.30043,
+    -0.08555, 0.01701,  -0.12544, 0.10969,  -0.48202, 0.07245,  0.20673,  0.11408,  0.04343,
+    -0.01815, -0.31594, -0.23632, -0.06258, -0.27474, 0.12180,  0.16613,  -0.37931, 0.30219,
+    0.15765,  0.25489,  0.17529,  -0.17020, -0.30060, 0.22058,  -0.02450, -0.42143, 0.49642,
+    0.46899,  -0.28552, -0.22549, -0.01333, 0.21567,  0.22251,  0.21639,  -0.19194, -0.19140,
+    -0.24106, 0.10952,  -0.11019, 0.29763,  -0.02039, -0.25748, 0.23169,  0.01357,  0.09802,
+    -0.19022, 0.37604,  -0.40777, 0.18131,  -0.10258, 0.29573,  -0.31773, 0.09069,  -0.02198,
+    -0.26594, 0.48302,  -0.10041, 0.20210,  -0.05609, -0.01169, -0.17339, 0.17862,  -0.22502,
+    0.29009,  -0.45160, 0.19771,  0.27634,  0.31695,  -0.09993, 0.17167,  0.12394,  0.28088,
+    -0.12502, -0.16967, -0.06296, -0.17036, 0.27320,  0.01595,  0.16955,  0.30146,  -0.15173,
+    -0.29807, 0.08178,  -0.06811, 0.21655,  0.26348,  0.06316,  0.45661,  -0.29756, -0.05742,
+    -0.14715, -0.03037, -0.16656, -0.08768, 0.38078,  0.40679,  -0.32779, -0.09106, 0.16107,
+    -0.07301, 0.07700,  -0.22694, -0.15692, -0.02548, 0.38749,  -0.12203, -0.02980, -0.22067,
+    0.00680,  -0.23058, -0.29112, 0.23032,  -0.16026, 0.23392,  -0.09990, 0.03628,  -0.42592,
+    -0.33474, -0.09499, -0.17442, -0.20110, 0.24618,  -0.06418, -0.06715, 0.40754,  0.29377,
+    0.29543,  -0.16832, -0.08468, 0.06491,  -0.01410, 0.19988,  0.24950,  0.14626,  -0.27851,
+    0.06079,  0.48134,  -0.13475, 0.25398,  0.11738,  0.23369,  -0.00661, -0.16811, -0.04557,
+    -0.12030, -0.39527, -0.35760, 0.01840,  -0.15941, 0.03290,  0.09988,  -0.08307, 0.06644,
+    -0.24637, 0.34112,  -0.08026, 0.00951,  0.27656,  0.16247,  0.28217,  0.17198,  -0.16389,
+    -0.03835, -0.02675, -0.08032, -0.21045, -0.38946, 0.23207,  0.10987,  -0.31674, -0.28653,
+    -0.27430, -0.29109, -0.00648, 0.38431,  -0.38478, -0.41195, -0.19364, -0.20977, -0.05524,
+    0.05558,  -0.20109, 0.11803,  -0.19884, 0.43318,  -0.39255, 0.26612,  -0.21771, 0.12471,
+    0.12856,  -0.15104, -0.11676, 0.17582,  -0.25330, 0.00298,  -0.31712, 0.21532,  -0.20319,
+    0.14507,  -0.04588, -0.22995, -0.06470, 0.18849,  -0.13444, 0.37107,  0.07387,  -0.14008,
+    0.09896,  0.13727,  -0.28417, -0.09461, -0.18703, 0.04080,  0.02343,  -0.49988, 0.17993,
+    0.23189,  -0.30581, -0.18334, -0.09667, -0.27699, -0.05998, 0.09118,  -0.32453, 0.46251,
+    0.41500,  -0.45314, -0.00544, 0.08529,  0.29099,  -0.00937, -0.31650, 0.26163,  0.14506,
+    0.37498,  -0.16454, 0.35215,  0.31642,  -0.09161, -0.31452, -0.04792, -0.04677, -0.19523,
+    0.27998,  0.05491,  0.44461,  -0.01258, -0.27887, 0.18361,  -0.04539, -0.02977, 0.30821,
+    0.29454,  -0.17932, 0.16193,  0.23934,  0.47923,  0.25373,  0.23258,  0.31484,  -0.17958,
+    -0.01136, 0.17681,  0.12869,  0.03235,  0.43762,  0.13734,  -0.09433, -0.03735, 0.17949,
+    0.14122,  -0.17814, 0.06359,  0.16044,  0.12249,  -0.22314, 0.40775,  0.05147,  0.12389,
+    0.04290,  -0.01642, 0.00082,  -0.18056, 0.02875,  0.32690,  0.17712,  0.34001,  -0.21581,
+    -0.01086, -0.18180, 0.17480,  -0.17774, -0.07503, 0.28438,  -0.19747, 0.29595,  -0.28002,
+    -0.02073, -0.16522, -0.18234, -0.20565, 0.29620,  0.07502,  0.01429,  -0.31418, 0.43693,
+    -0.12212, 0.11178,  -0.28503, 0.04683,  0.00072,  0.05566,  0.18857,  0.26101,  -0.38891,
+    -0.21216, -0.21850, -0.15147, -0.30749, -0.23762, 0.14984,  0.03535,  -0.02862, -0.00105,
+    -0.39907, -0.06909, -0.36094, 0.21717,  0.15930,  -0.18924, 0.13741,  0.01039,  0.13613,
+    0.00659,  0.07676,  -0.13711, 0.24285,  -0.07564, -0.28349, -0.15658, 0.03135,  -0.30909,
+    -0.22534, 0.17363,  -0.19376, 0.26038,  0.05546,  -0.22607, 0.32420,  -0.02552, -0.05400,
+    0.13388,  0.04643,  -0.31535, -0.06181, 0.30237,  -0.04680, -0.29441, 0.12231,  0.03960,
+    -0.01188, 0.01406,  0.25402,  0.03315,  0.25026,  -0.10922};
+
+const double gu_data2[] = { // raw data 300 items
+    0.26599, 0.41329, 0.31846, 0.92590, 0.43050, 0.17466, 0.02322, 0.72621, 0.37921, 0.70597,
+    0.97098, 0.14023, 0.57619, 0.09938, 0.02281, 0.92341, 0.72654, 0.71000, 0.76687, 0.70182,
+    0.88752, 0.49524, 0.42549, 0.42806, 0.57615, 0.76051, 0.15341, 0.47457, 0.60066, 0.40880,
+    0.20668, 0.41949, 0.97620, 0.94318, 0.71491, 0.56402, 0.23553, 0.94387, 0.78567, 0.06362,
+    0.85252, 0.86262, 0.25190, 0.03274, 0.93216, 0.37971, 0.08797, 0.14596, 0.73871, 0.06574,
+    0.67447, 0.28575, 0.43911, 0.92133, 0.12327, 0.87762, 0.71060, 0.07141, 0.55443, 0.53310,
+    0.91529, 0.25121, 0.07593, 0.94490, 0.28656, 0.82174, 0.68887, 0.67337, 0.99291, 0.03316,
+    0.02849, 0.33891, 0.25594, 0.90071, 0.01248, 0.67871, 0.65953, 0.65369, 0.97574, 0.31578,
+    0.23678, 0.39220, 0.06706, 0.80943, 0.57694, 0.08220, 0.18151, 0.19969, 0.37096, 0.37858,
+    0.70153, 0.46816, 0.76511, 0.02520, 0.39387, 0.25527, 0.39050, 0.60141, 0.30322, 0.46195,
+    0.12025, 0.33616, 0.04174, 0.00196, 0.68886, 0.74445, 0.15869, 0.18994, 0.95195, 0.62874,
+    0.82874, 0.53369, 0.34383, 0.50752, 0.97023, 0.22695, 0.62407, 0.25840, 0.71279, 0.28785,
+    0.31611, 0.20391, 0.19702, 0.40760, 0.85158, 0.68369, 0.63760, 0.09879, 0.11924, 0.32920,
+    0.53052, 0.15900, 0.21229, 0.84080, 0.33933, 0.93651, 0.42705, 0.06199, 0.50092, 0.47192,
+    0.57152, 0.01818, 0.31404, 0.50173, 0.87725, 0.50530, 0.10717, 0.04035, 0.32901, 0.33538,
+    0.04780, 0.40984, 0.78216, 0.91288, 0.11314, 0.25248, 0.23823, 0.74001, 0.48089, 0.55531,
+    0.82486, 0.01058, 0.05409, 0.44357, 0.52641, 0.68188, 0.94629, 0.61627, 0.33037, 0.11961,
+    0.57988, 0.19653, 0.91902, 0.59838, 0.52974, 0.28364, 0.45767, 0.65836, 0.63045, 0.76140,
+    0.27918, 0.27256, 0.46035, 0.77418, 0.92918, 0.14095, 0.89645, 0.25146, 0.21172, 0.47910,
+    0.95451, 0.34377, 0.29927, 0.79220, 0.97654, 0.67591, 0.44385, 0.38434, 0.44860, 0.28170,
+    0.90712, 0.20337, 0.00292, 0.55046, 0.62255, 0.45127, 0.80896, 0.43965, 0.59145, 0.23801,
+    0.33601, 0.30119, 0.89935, 0.40850, 0.98226, 0.75430, 0.68318, 0.65407, 0.68067, 0.32942,
+    0.11756, 0.27626, 0.83879, 0.72174, 0.75430, 0.13702, 0.03402, 0.58781, 0.07393, 0.23067,
+    0.92537, 0.29445, 0.43437, 0.47685, 0.54548, 0.66082, 0.23805, 0.60208, 0.94337, 0.21363,
+    0.72637, 0.57181, 0.77679, 0.63931, 0.72860, 0.38901, 0.94920, 0.04535, 0.12863, 0.40550,
+    0.90095, 0.21418, 0.13953, 0.99639, 0.02526, 0.70018, 0.21828, 0.20294, 0.20191, 0.30954,
+    0.39490, 0.68955, 0.11506, 0.15748, 0.40252, 0.91680, 0.61547, 0.78443, 0.19693, 0.67630,
+    0.56552, 0.58556, 0.53554, 0.53507, 0.09831, 0.21229, 0.83135, 0.26375, 0.89287, 0.97069,
+    0.70615, 0.42041, 0.43117, 0.21291, 0.26086, 0.26978, 0.77340, 0.43833, 0.46179, 0.54418,
+    0.67878, 0.42776, 0.61454, 0.55915, 0.36363, 0.31999, 0.42442, 0.86649, 0.62513, 0.02047};
 
 class TestRunnable
 {
 public:
   const std::string name;
-  int dim; // dimension of the solved problem
+  int dim;  // dimension of the solved problem
   int nvar; // number of variable of the solved problem
-  TestRunnable(std::string n, int d, int nv)
-    : name{std::move(n)}, dim(d), nvar(nv)
+  TestRunnable(std::string n, int d, int nv) : name {std::move(n)}, dim(d), nvar(nv)
   {
   }
   virtual ~TestRunnable() = default;
   bool test() const;
   virtual bool run() const = 0;
+
 protected:
-  static double korder_unfold_fold(int maxdim, int unfold_dim,
-                                   int nstat, int npred, int nboth, int forw,
-                                   const TwoDMatrix &gy, const TwoDMatrix &gu,
-                                   const TwoDMatrix &v);
+  static double korder_unfold_fold(int maxdim, int unfold_dim, int nstat, int npred, int nboth,
+                                   int forw, const TwoDMatrix& gy, const TwoDMatrix& gu,
+                                   const TwoDMatrix& v);
 };
 
 bool
@@ -289,8 +279,9 @@ TestRunnable::test() const
   auto end_real = std::chrono::steady_clock::now();
   std::chrono::duration<double> duration = end_real - start_real;
   std::cout << "CPU time  " << std::setprecision(4) << std::setw(8)
-            << static_cast<double>(end-start)/CLOCKS_PER_SEC << " (CPU seconds)\n"
-            << "Real time " << std::setw(8) << duration.count() << " (seconds).....................";
+            << static_cast<double>(end - start) / CLOCKS_PER_SEC << " (CPU seconds)\n"
+            << "Real time " << std::setw(8) << duration.count()
+            << " (seconds).....................";
   if (passed)
     std::cout << "passed\n\n";
   else
@@ -299,20 +290,18 @@ TestRunnable::test() const
 }
 
 double
-TestRunnable::korder_unfold_fold(int maxdim, int unfold_dim,
-                                 int nstat, int npred, int nboth, int nforw,
-                                 const TwoDMatrix &gy, const TwoDMatrix &gu,
-                                 const TwoDMatrix &v)
+TestRunnable::korder_unfold_fold(int maxdim, int unfold_dim, int nstat, int npred, int nboth,
+                                 int nforw, const TwoDMatrix& gy, const TwoDMatrix& gu,
+                                 const TwoDMatrix& v)
 {
   TensorContainer<FSSparseTensor> c(1);
-  int ny = nstat+npred+nboth+nforw;
+  int ny = nstat + npred + nboth + nforw;
   int nu = v.nrows();
-  int nz = nboth+nforw+ny+nboth+npred+nu;
+  int nz = nboth + nforw + ny + nboth + npred + nu;
   SparseGenerator::fillContainer(c, maxdim, nz, ny, 5.0);
   for (int d = 1; d <= maxdim; d++)
-    std::cout << "\ttensor fill for dim=" << d << " is:   "
-              << std::setprecision(2) << std::setw(6) << std::fixed
-              << c.get(Symmetry{d}).getFillFactor()*100.0 << " %\n"
+    std::cout << "\ttensor fill for dim=" << d << " is:   " << std::setprecision(2) << std::setw(6)
+              << std::fixed << c.get(Symmetry {d}).getFillFactor() * 100.0 << " %\n"
               << std::defaultfloat;
   Journal jr("out.txt");
   KOrder kord(nstat, npred, nboth, nforw, c, gy, gu, v, jr);
@@ -322,14 +311,14 @@ TestRunnable::korder_unfold_fold(int maxdim, int unfold_dim,
     {
       clock_t pertime = clock();
       kord.performStep<Storage::unfold>(d);
-      pertime = clock()-pertime;
+      pertime = clock() - pertime;
       std::cout << "\ttime for unfolded step dim=" << d << ": " << std::setprecision(4)
-                << static_cast<double>(pertime)/CLOCKS_PER_SEC << std::endl;
+                << static_cast<double>(pertime) / CLOCKS_PER_SEC << std::endl;
       clock_t checktime = clock();
       double err = kord.check<Storage::unfold>(d);
-      checktime = clock()-checktime;
+      checktime = clock() - checktime;
       std::cout << "\ttime for step check dim=" << d << ":    " << std::setprecision(4)
-                << static_cast<double>(checktime)/CLOCKS_PER_SEC << '\n'
+                << static_cast<double>(checktime) / CLOCKS_PER_SEC << '\n'
                 << "\tmax error in step dim=" << d << ":      " << std::setprecision(6) << err
                 << std::endl;
       maxerror = std::max(err, maxerror);
@@ -339,22 +328,22 @@ TestRunnable::korder_unfold_fold(int maxdim, int unfold_dim,
     {
       clock_t swtime = clock();
       kord.switchToFolded();
-      swtime = clock()-swtime;
+      swtime = clock() - swtime;
       std::cout << "\ttime for switching dim=" << unfold_dim << ":     " << std::setprecision(4)
-                << static_cast<double>(swtime)/CLOCKS_PER_SEC << std::endl;
+                << static_cast<double>(swtime) / CLOCKS_PER_SEC << std::endl;
 
-      for (int d = unfold_dim+1; d <= maxdim; d++)
+      for (int d = unfold_dim + 1; d <= maxdim; d++)
         {
           clock_t pertime = clock();
           kord.performStep<Storage::fold>(d);
-          pertime = clock()-pertime;
+          pertime = clock() - pertime;
           std::cout << "\ttime for folded step dim=" << d << ":   " << std::setprecision(4)
-                    << static_cast<double>(pertime)/CLOCKS_PER_SEC << std::endl;
+                    << static_cast<double>(pertime) / CLOCKS_PER_SEC << std::endl;
           clock_t checktime = clock();
           double err = kord.check<Storage::fold>(d);
-          checktime = clock()-checktime;
+          checktime = clock() - checktime;
           std::cout << "\ttime for step check dim=" << d << ":    " << std::setprecision(4)
-                    << static_cast<double>(checktime)/CLOCKS_PER_SEC << '\n'
+                    << static_cast<double>(checktime) / CLOCKS_PER_SEC << '\n'
                     << "\tmax error in step dim=" << d << ":      " << std::setprecision(6) << err
                     << std::endl;
           maxerror = std::max(err, maxerror);
@@ -366,20 +355,18 @@ TestRunnable::korder_unfold_fold(int maxdim, int unfold_dim,
 class UnfoldKOrderSmall : public TestRunnable
 {
 public:
-  UnfoldKOrderSmall()
-    : TestRunnable("unfold-3 fold-4 korder (stat=2,pred=3,both=1,forw=2,u=3,dim=4)",
-                   4, 18)
+  UnfoldKOrderSmall() :
+      TestRunnable("unfold-3 fold-4 korder (stat=2,pred=3,both=1,forw=2,u=3,dim=4)", 4, 18)
   {
   }
 
   bool
   run() const override
   {
-    TwoDMatrix gy{make_matrix(8, 4, gy_data)};
-    TwoDMatrix gu{make_matrix(8, 3, gu_data)};
-    TwoDMatrix v{make_matrix(3, 3, vdata)};
-    double err = korder_unfold_fold(4, 3, 2, 3, 1, 2,
-                                    gy, gu, v);
+    TwoDMatrix gy {make_matrix(8, 4, gy_data)};
+    TwoDMatrix gu {make_matrix(8, 3, gu_data)};
+    TwoDMatrix v {make_matrix(3, 3, vdata)};
+    double err = korder_unfold_fold(4, 3, 2, 3, 1, 2, gy, gu, v);
 
     return err < 5e-7;
   }
@@ -389,22 +376,20 @@ public:
 class UnfoldKOrderSW : public TestRunnable
 {
 public:
-  UnfoldKOrderSW()
-    : TestRunnable("unfold S&W korder (stat=5,pred=12,both=8,forw=5,u=10,dim=4)",
-                   4, 73)
+  UnfoldKOrderSW() :
+      TestRunnable("unfold S&W korder (stat=5,pred=12,both=8,forw=5,u=10,dim=4)", 4, 73)
   {
   }
 
   bool
   run() const override
   {
-    TwoDMatrix gy{make_matrix(30, 20, gy_data2)};
-    TwoDMatrix gu{make_matrix(30, 10, gu_data2)};
-    TwoDMatrix v{make_matrix(10, 10, vdata2)};
+    TwoDMatrix gy {make_matrix(30, 20, gy_data2)};
+    TwoDMatrix gu {make_matrix(30, 10, gu_data2)};
+    TwoDMatrix v {make_matrix(10, 10, vdata2)};
     v.mult(0.001);
     gu.mult(.01);
-    double err = korder_unfold_fold(4, 4, 5, 12, 8, 5,
-                                    gy, gu, v);
+    double err = korder_unfold_fold(4, 4, 5, 12, 8, 5, gy, gu, v);
 
     return err < 0.5;
   }
@@ -413,22 +398,20 @@ public:
 class UnfoldFoldKOrderSW : public TestRunnable
 {
 public:
-  UnfoldFoldKOrderSW()
-    : TestRunnable("unfold-2 fold-3 S&W korder (stat=5,pred=12,both=8,forw=5,u=10,dim=3)",
-                   4, 73)
+  UnfoldFoldKOrderSW() :
+      TestRunnable("unfold-2 fold-3 S&W korder (stat=5,pred=12,both=8,forw=5,u=10,dim=3)", 4, 73)
   {
   }
 
   bool
   run() const override
   {
-    TwoDMatrix gy{make_matrix(30, 20, gy_data2)};
-    TwoDMatrix gu{make_matrix(30, 10, gu_data2)};
-    TwoDMatrix v{make_matrix(10, 10, vdata2)};
+    TwoDMatrix gy {make_matrix(30, 20, gy_data2)};
+    TwoDMatrix gu {make_matrix(30, 10, gu_data2)};
+    TwoDMatrix v {make_matrix(10, 10, vdata2)};
     v.mult(0.001);
     gu.mult(.01);
-    double err = korder_unfold_fold(4, 3, 5, 12, 8, 5,
-                                    gy, gu, v);
+    double err = korder_unfold_fold(4, 3, 5, 12, 8, 5, gy, gu, v);
 
     return err < 0.5;
   }
@@ -446,7 +429,7 @@ main()
   // Find maximum dimension and maximum nvar
   int dmax = 0;
   int nvmax = 0;
-  for (const auto &test : all_tests)
+  for (const auto& test : all_tests)
     {
       if (dmax < test->dim)
         dmax = test->dim;
@@ -457,19 +440,19 @@ main()
 
   // Launch the tests
   int success = 0;
-  for (const auto &test : all_tests)
+  for (const auto& test : all_tests)
     {
       try
         {
           if (test->test())
             success++;
         }
-      catch (const TLException &e)
+      catch (const TLException& e)
         {
           std::cout << "Caught TL exception in <" << test->name << ">:" << std::endl;
           e.print();
         }
-      catch (SylvException &e)
+      catch (SylvException& e)
         {
           std::cout << "Caught Sylv exception in <" << test->name << ">:" << std::endl;
           e.printMessage();
@@ -477,8 +460,8 @@ main()
     }
 
   int nfailed = all_tests.size() - success;
-  std::cout << "There were " << nfailed << " tests that failed out of "
-            << all_tests.size() << " tests run." << std::endl;
+  std::cout << "There were " << nfailed << " tests that failed out of " << all_tests.size()
+            << " tests run." << std::endl;
 
   if (nfailed)
     return EXIT_FAILURE;
diff --git a/mex/sources/libkorder/sylv/BlockDiagonal.cc b/mex/sources/libkorder/sylv/BlockDiagonal.cc
index f7aa183c97ec8e236026945637972bf59f416a80..48a5f06c59bfa34e1bd1135b6c8cf5071344088d 100644
--- a/mex/sources/libkorder/sylv/BlockDiagonal.cc
+++ b/mex/sources/libkorder/sylv/BlockDiagonal.cc
@@ -24,9 +24,8 @@
 #include <iostream>
 #include <utility>
 
-BlockDiagonal::BlockDiagonal(ConstVector d, int d_size)
-  : QuasiTriangular(std::move(d), d_size),
-    row_len(d_size), col_len(d_size)
+BlockDiagonal::BlockDiagonal(ConstVector d, int d_size) :
+    QuasiTriangular(std::move(d), d_size), row_len(d_size), col_len(d_size)
 {
   for (int i = 0; i < d_size; i++)
     {
@@ -35,9 +34,8 @@ BlockDiagonal::BlockDiagonal(ConstVector d, int d_size)
     }
 }
 
-BlockDiagonal::BlockDiagonal(const QuasiTriangular &t)
-  : QuasiTriangular(t),
-    row_len(t.nrows()), col_len(t.nrows())
+BlockDiagonal::BlockDiagonal(const QuasiTriangular& t) :
+    QuasiTriangular(t), row_len(t.nrows()), col_len(t.nrows())
 {
   for (int i = 0; i < t.nrows(); i++)
     {
@@ -73,57 +71,53 @@ BlockDiagonal::setZeroBlockEdge(diag_iter edge)
 
   int iedge = edge->getIndex();
   for (diag_iter run = diag_begin(); run != edge; ++run)
-    if (int ind {run->getIndex()};
-        row_len[ind] > iedge)
+    if (int ind {run->getIndex()}; row_len[ind] > iedge)
       {
         row_len[ind] = iedge;
         if (!run->isReal())
-          row_len[ind+1] = iedge;
+          row_len[ind + 1] = iedge;
       }
   for (diag_iter run = edge; run != diag_end(); ++run)
-    if (int ind {run->getIndex()};
-        col_len[ind] < iedge)
+    if (int ind {run->getIndex()}; col_len[ind] < iedge)
       {
         col_len[ind] = iedge;
         if (!run->isReal())
-          col_len[ind+1] = iedge;
+          col_len[ind + 1] = iedge;
       }
 }
 
 BlockDiagonal::const_col_iter
-BlockDiagonal::col_begin(const DiagonalBlock &b) const
+BlockDiagonal::col_begin(const DiagonalBlock& b) const
 {
   int jbar = b.getIndex();
   int d_size = diagonal.getSize();
-  return const_col_iter(&getData()[jbar*d_size + col_len[jbar]], d_size,
-                        b.isReal(), col_len[jbar]);
+  return const_col_iter(&getData()[jbar * d_size + col_len[jbar]], d_size, b.isReal(),
+                        col_len[jbar]);
 }
 
 BlockDiagonal::col_iter
-BlockDiagonal::col_begin(const DiagonalBlock &b)
+BlockDiagonal::col_begin(const DiagonalBlock& b)
 {
   int jbar = b.getIndex();
   int d_size = diagonal.getSize();
-  return col_iter(&getData()[jbar*d_size + col_len[jbar]], d_size,
-                  b.isReal(), col_len[jbar]);
+  return col_iter(&getData()[jbar * d_size + col_len[jbar]], d_size, b.isReal(), col_len[jbar]);
 }
 
 BlockDiagonal::const_row_iter
-BlockDiagonal::row_end(const DiagonalBlock &b) const
+BlockDiagonal::row_end(const DiagonalBlock& b) const
 {
   int jbar = b.getIndex();
   int d_size = diagonal.getSize();
-  return const_row_iter(&getData()[d_size*row_len[jbar]+jbar], d_size,
-                        b.isReal(), row_len[jbar]);
+  return const_row_iter(&getData()[d_size * row_len[jbar] + jbar], d_size, b.isReal(),
+                        row_len[jbar]);
 }
 
 BlockDiagonal::row_iter
-BlockDiagonal::row_end(const DiagonalBlock &b)
+BlockDiagonal::row_end(const DiagonalBlock& b)
 {
   int jbar = b.getIndex();
   int d_size = diagonal.getSize();
-  return row_iter(&getData()[d_size*row_len[jbar]+jbar], d_size,
-                  b.isReal(), row_len[jbar]);
+  return row_iter(&getData()[d_size * row_len[jbar] + jbar], d_size, b.isReal(), row_len[jbar]);
 }
 
 int
@@ -141,8 +135,7 @@ BlockDiagonal::findBlockStart(const_diag_iter from) const
   if (from != diag_end())
     {
       ++from;
-      while (from != diag_end()
-             && col_len[from->getIndex()] != from->getIndex())
+      while (from != diag_end() && col_len[from->getIndex()] != from->getIndex())
         ++from;
     }
   return from;
@@ -160,7 +153,7 @@ BlockDiagonal::getLargestBlock() const
       int ei = diagonal.getSize();
       if (end != diag_end())
         ei = end->getIndex();
-      largest = std::max(largest, ei-si);
+      largest = std::max(largest, ei - si);
       start = end;
       end = findBlockStart(start);
     }
@@ -168,19 +161,19 @@ BlockDiagonal::getLargestBlock() const
 }
 
 void
-BlockDiagonal::savePartOfX(int si, int ei, const KronVector &x, Vector &work)
+BlockDiagonal::savePartOfX(int si, int ei, const KronVector& x, Vector& work)
 {
   for (int i = si; i < ei; i++)
     {
       ConstKronVector xi(x, i);
-      Vector target(work, (i-si)*xi.length(), xi.length());
+      Vector target(work, (i - si) * xi.length(), xi.length());
       target = xi;
     }
 }
 
 void
-BlockDiagonal::multKronBlock(const_diag_iter start, const_diag_iter end,
-                             KronVector &x, Vector &work) const
+BlockDiagonal::multKronBlock(const_diag_iter start, const_diag_iter end, KronVector& x,
+                             Vector& work) const
 {
   int si = start->getIndex();
   int ei = diagonal.getSize();
@@ -189,28 +182,27 @@ BlockDiagonal::multKronBlock(const_diag_iter start, const_diag_iter end,
   savePartOfX(si, ei, x, work);
 
   for (const_diag_iter di = start; di != end; ++di)
-    if (int jbar {di->getIndex()};
-        di->isReal())
+    if (int jbar {di->getIndex()}; di->isReal())
       {
         KronVector xi(x, jbar);
         xi.zeros();
-        Vector wi(work, (jbar-si)*xi.length(), xi.length());
+        Vector wi(work, (jbar - si) * xi.length(), xi.length());
         xi.add(*(di->getAlpha()), wi);
         for (const_row_iter ri = row_begin(*di); ri != row_end(*di); ++ri)
           {
             int col = ri.getCol();
-            Vector wj(work, (col-si)*xi.length(), xi.length());
+            Vector wj(work, (col - si) * xi.length(), xi.length());
             xi.add(*ri, wj);
           }
       }
     else
       {
         KronVector xi(x, jbar);
-        KronVector xii(x, jbar+1);
+        KronVector xii(x, jbar + 1);
         xi.zeros();
         xii.zeros();
-        Vector wi(work, (jbar-si)*xi.length(), xi.length());
-        Vector wii(work, (jbar+1-si)*xi.length(), xi.length());
+        Vector wi(work, (jbar - si) * xi.length(), xi.length());
+        Vector wii(work, (jbar + 1 - si) * xi.length(), xi.length());
         xi.add(*(di->getAlpha()), wi);
         xi.add(di->getBeta1(), wii);
         xii.add(di->getBeta2(), wi);
@@ -218,7 +210,7 @@ BlockDiagonal::multKronBlock(const_diag_iter start, const_diag_iter end,
         for (const_row_iter ri = row_begin(*di); ri != row_end(*di); ++ri)
           {
             int col = ri.getCol();
-            Vector wj(work, (col-si)*xi.length(), xi.length());
+            Vector wj(work, (col - si) * xi.length(), xi.length());
             xi.add(ri.a(), wj);
             xii.add(ri.b(), wj);
           }
@@ -226,8 +218,8 @@ BlockDiagonal::multKronBlock(const_diag_iter start, const_diag_iter end,
 }
 
 void
-BlockDiagonal::multKronBlockTrans(const_diag_iter start, const_diag_iter end,
-                                  KronVector &x, Vector &work) const
+BlockDiagonal::multKronBlockTrans(const_diag_iter start, const_diag_iter end, KronVector& x,
+                                  Vector& work) const
 {
   int si = start->getIndex();
   int ei = diagonal.getSize();
@@ -236,28 +228,27 @@ BlockDiagonal::multKronBlockTrans(const_diag_iter start, const_diag_iter end,
   savePartOfX(si, ei, x, work);
 
   for (const_diag_iter di = start; di != end; ++di)
-    if (int jbar {di->getIndex()};
-        di->isReal())
+    if (int jbar {di->getIndex()}; di->isReal())
       {
         KronVector xi(x, jbar);
         xi.zeros();
-        Vector wi(work, (jbar-si)*xi.length(), xi.length());
+        Vector wi(work, (jbar - si) * xi.length(), xi.length());
         xi.add(*(di->getAlpha()), wi);
         for (const_col_iter ci = col_begin(*di); ci != col_end(*di); ++ci)
           {
             int row = ci.getRow();
-            Vector wj(work, (row-si)*xi.length(), xi.length());
+            Vector wj(work, (row - si) * xi.length(), xi.length());
             xi.add(*ci, wj);
           }
       }
     else
       {
         KronVector xi(x, jbar);
-        KronVector xii(x, jbar+1);
+        KronVector xii(x, jbar + 1);
         xi.zeros();
         xii.zeros();
-        Vector wi(work, (jbar-si)*xi.length(), xi.length());
-        Vector wii(work, (jbar+1-si)*xi.length(), xi.length());
+        Vector wi(work, (jbar - si) * xi.length(), xi.length());
+        Vector wii(work, (jbar + 1 - si) * xi.length(), xi.length());
         xi.add(*(di->getAlpha()), wi);
         xi.add(di->getBeta2(), wii);
         xii.add(di->getBeta1(), wi);
@@ -265,7 +256,7 @@ BlockDiagonal::multKronBlockTrans(const_diag_iter start, const_diag_iter end,
         for (const_col_iter ci = col_begin(*di); ci != col_end(*di); ++ci)
           {
             int row = ci.getRow();
-            Vector wj(work, (row-si)*xi.length(), xi.length());
+            Vector wj(work, (row - si) * xi.length(), xi.length());
             xi.add(ci.a(), wj);
             xii.add(ci.b(), wj);
           }
@@ -273,10 +264,10 @@ BlockDiagonal::multKronBlockTrans(const_diag_iter start, const_diag_iter end,
 }
 
 void
-BlockDiagonal::multKron(KronVector &x) const
+BlockDiagonal::multKron(KronVector& x) const
 {
   int largest = getLargestBlock();
-  Vector work(largest *x.getN()*power(x.getM(), x.getDepth()-1));
+  Vector work(largest * x.getN() * power(x.getM(), x.getDepth() - 1));
   const_diag_iter start = diag_begin();
   const_diag_iter end = findBlockStart(start);
   while (start != diag_end())
@@ -288,10 +279,10 @@ BlockDiagonal::multKron(KronVector &x) const
 }
 
 void
-BlockDiagonal::multKronTrans(KronVector &x) const
+BlockDiagonal::multKronTrans(KronVector& x) const
 {
   int largest = getLargestBlock();
-  Vector work(largest *x.getN()*power(x.getM(), x.getDepth()-1));
+  Vector work(largest * x.getN() * power(x.getM(), x.getDepth() - 1));
   const_diag_iter start = diag_begin();
   const_diag_iter end = findBlockStart(start);
   while (start != diag_end())
@@ -315,14 +306,15 @@ BlockDiagonal::printInfo() const
       int ei = diagonal.getSize();
       if (end != diag_end())
         ei = end->getIndex();
-      std::cout << ' ' << ei-si;
+      std::cout << ' ' << ei - si;
       num_blocks++;
       start = end;
       end = findBlockStart(start);
     }
   std::cout << std::endl
             << "Num blocks: " << num_blocks << std::endl
-            << "There are " << getNumZeros() << " zeros out of " << getNumOffdiagonal() << std::endl;
+            << "There are " << getNumZeros() << " zeros out of " << getNumOffdiagonal()
+            << std::endl;
 }
 
 int
diff --git a/mex/sources/libkorder/sylv/BlockDiagonal.hh b/mex/sources/libkorder/sylv/BlockDiagonal.hh
index e5e333366f7baacde1f454e96885df58ce502fa3..416308971c3734ecdc2f1d581ccc0699983e28ab 100644
--- a/mex/sources/libkorder/sylv/BlockDiagonal.hh
+++ b/mex/sources/libkorder/sylv/BlockDiagonal.hh
@@ -29,16 +29,18 @@
 class BlockDiagonal : public QuasiTriangular
 {
   std::vector<int> row_len, col_len;
+
 public:
   BlockDiagonal(ConstVector d, int d_size);
-  BlockDiagonal(const BlockDiagonal &b) = default;
-  explicit BlockDiagonal(const QuasiTriangular &t);
-  BlockDiagonal &operator=(const QuasiTriangular &t)
+  BlockDiagonal(const BlockDiagonal& b) = default;
+  explicit BlockDiagonal(const QuasiTriangular& t);
+  BlockDiagonal&
+  operator=(const QuasiTriangular& t)
   {
     GeneralMatrix::operator=(t);
     return *this;
   }
-  BlockDiagonal &operator=(const BlockDiagonal &b) = default;
+  BlockDiagonal& operator=(const BlockDiagonal& b) = default;
   ~BlockDiagonal() override = default;
   void setZeroBlockEdge(diag_iter edge);
   int getNumZeros() const;
@@ -46,26 +48,26 @@ public:
   int getLargestBlock() const;
   void printInfo() const;
 
-  void multKron(KronVector &x) const override;
-  void multKronTrans(KronVector &x) const override;
+  void multKron(KronVector& x) const override;
+  void multKronTrans(KronVector& x) const override;
 
-  const_col_iter col_begin(const DiagonalBlock &b) const override;
-  col_iter col_begin(const DiagonalBlock &b) override;
-  const_row_iter row_end(const DiagonalBlock &b) const override;
-  row_iter row_end(const DiagonalBlock &b) override;
+  const_col_iter col_begin(const DiagonalBlock& b) const override;
+  col_iter col_begin(const DiagonalBlock& b) override;
+  const_row_iter row_end(const DiagonalBlock& b) const override;
+  row_iter row_end(const DiagonalBlock& b) override;
   std::unique_ptr<QuasiTriangular>
   clone() const override
   {
     return std::make_unique<BlockDiagonal>(*this);
   }
+
 private:
   void setZerosToRU(diag_iter edge);
   const_diag_iter findBlockStart(const_diag_iter from) const;
-  static void savePartOfX(int si, int ei, const KronVector &x, Vector &work);
-  void multKronBlock(const_diag_iter start, const_diag_iter end,
-                     KronVector &x, Vector &work) const;
-  void multKronBlockTrans(const_diag_iter start, const_diag_iter end,
-                          KronVector &x, Vector &work) const;
+  static void savePartOfX(int si, int ei, const KronVector& x, Vector& work);
+  void multKronBlock(const_diag_iter start, const_diag_iter end, KronVector& x, Vector& work) const;
+  void multKronBlockTrans(const_diag_iter start, const_diag_iter end, KronVector& x,
+                          Vector& work) const;
 };
 
 #endif /* BLOCK_DIAGONAL_H */
diff --git a/mex/sources/libkorder/sylv/GeneralMatrix.cc b/mex/sources/libkorder/sylv/GeneralMatrix.cc
index 65a84893cc4a81db4829fd023f5f015de3613a04..99d1e6be196125518cd8cb7a7087c2d3c6a29451 100644
--- a/mex/sources/libkorder/sylv/GeneralMatrix.cc
+++ b/mex/sources/libkorder/sylv/GeneralMatrix.cc
@@ -18,43 +18,43 @@
  * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#include "SylvException.hh"
 #include "GeneralMatrix.hh"
+#include "SylvException.hh"
 
 #include <dynblas.h>
 #include <dynlapack.h>
 
-#include <iostream>
-#include <iomanip>
-#include <cstdlib>
 #include <cmath>
+#include <cstdlib>
+#include <iomanip>
+#include <iostream>
 #include <limits>
 
-GeneralMatrix::GeneralMatrix(const GeneralMatrix &m)
-  : data(m.rows*m.cols), rows(m.rows), cols(m.cols), ld(m.rows)
+GeneralMatrix::GeneralMatrix(const GeneralMatrix& m) :
+    data(m.rows * m.cols), rows(m.rows), cols(m.cols), ld(m.rows)
 {
   copy(m);
 }
 
-GeneralMatrix::GeneralMatrix(const ConstGeneralMatrix &m)
-  : data(m.rows*m.cols), rows(m.rows), cols(m.cols), ld(m.rows)
+GeneralMatrix::GeneralMatrix(const ConstGeneralMatrix& m) :
+    data(m.rows * m.cols), rows(m.rows), cols(m.cols), ld(m.rows)
 {
   copy(m);
 }
 
-GeneralMatrix::GeneralMatrix(const GeneralMatrix &m, int i, int j, int nrows, int ncols)
-  : data(nrows*ncols), rows(nrows), cols(ncols), ld(nrows)
+GeneralMatrix::GeneralMatrix(const GeneralMatrix& m, int i, int j, int nrows, int ncols) :
+    data(nrows * ncols), rows(nrows), cols(ncols), ld(nrows)
 {
   copy(m, i, j);
 }
 
-GeneralMatrix::GeneralMatrix(GeneralMatrix &m, int i, int j, int nrows, int ncols)
-  : data(m.data, m.ld*j+i, m.ld*(ncols-1)+nrows), rows(nrows), cols(ncols), ld(m.ld)
+GeneralMatrix::GeneralMatrix(GeneralMatrix& m, int i, int j, int nrows, int ncols) :
+    data(m.data, m.ld * j + i, m.ld * (ncols - 1) + nrows), rows(nrows), cols(ncols), ld(m.ld)
 {
 }
 
-GeneralMatrix &
-GeneralMatrix::operator=(const ConstGeneralMatrix &m)
+GeneralMatrix&
+GeneralMatrix::operator=(const ConstGeneralMatrix& m)
 {
   data = m.data;
   rows = m.rows;
@@ -66,32 +66,31 @@ GeneralMatrix::operator=(const ConstGeneralMatrix &m)
 Vector
 GeneralMatrix::getRow(int row)
 {
-  return Vector{data, row, ld, cols};
+  return Vector {data, row, ld, cols};
 }
 
 Vector
 GeneralMatrix::getCol(int col)
 {
-  return Vector{data, ld*col, rows};
+  return Vector {data, ld * col, rows};
 }
 
 ConstVector
 GeneralMatrix::getRow(int row) const
 {
-  return ConstVector{data, row, ld, cols};
+  return ConstVector {data, row, ld, cols};
 }
 
 ConstVector
 GeneralMatrix::getCol(int col) const
 {
-  return ConstVector{data, ld*col, rows};
+  return ConstVector {data, ld * col, rows};
 }
 
 void
-GeneralMatrix::place(const ConstGeneralMatrix &m, int i, int j)
+GeneralMatrix::place(const ConstGeneralMatrix& m, int i, int j)
 {
-  if (i + m.nrows() > nrows()
-      || j + m.ncols() > ncols())
+  if (i + m.nrows() > nrows() || j + m.ncols() > ncols())
     throw SYLV_MES_EXCEPTION("Bad submatrix placement, matrix dimensions exceeded.");
 
   GeneralMatrix tmpsub(*this, i, j, m.nrows(), m.ncols());
@@ -99,42 +98,41 @@ GeneralMatrix::place(const ConstGeneralMatrix &m, int i, int j)
 }
 
 void
-GeneralMatrix::mult(const ConstGeneralMatrix &a, const ConstGeneralMatrix &b)
+GeneralMatrix::mult(const ConstGeneralMatrix& a, const ConstGeneralMatrix& b)
 {
   gemm("N", a, "N", b, 1.0, 0.0);
 }
 
 void
-GeneralMatrix::multAndAdd(const ConstGeneralMatrix &a, const ConstGeneralMatrix &b,
-                          double mult)
+GeneralMatrix::multAndAdd(const ConstGeneralMatrix& a, const ConstGeneralMatrix& b, double mult)
 {
   gemm("N", a, "N", b, mult, 1.0);
 }
 
 void
-GeneralMatrix::multAndAdd(const ConstGeneralMatrix &a, const ConstGeneralMatrix &b,
-                          [[maybe_unused]] const std::string &dum, double mult)
+GeneralMatrix::multAndAdd(const ConstGeneralMatrix& a, const ConstGeneralMatrix& b,
+                          [[maybe_unused]] const std::string& dum, double mult)
 {
   gemm("N", a, "T", b, mult, 1.0);
 }
 
 void
-GeneralMatrix::multAndAdd(const ConstGeneralMatrix &a, [[maybe_unused]] const std::string &dum,
-                          const ConstGeneralMatrix &b, double mult)
+GeneralMatrix::multAndAdd(const ConstGeneralMatrix& a, [[maybe_unused]] const std::string& dum,
+                          const ConstGeneralMatrix& b, double mult)
 {
   gemm("T", a, "N", b, mult, 1.0);
 }
 
 void
-GeneralMatrix::multAndAdd(const ConstGeneralMatrix &a, [[maybe_unused]] const std::string &dum1,
-                          const ConstGeneralMatrix &b, [[maybe_unused]] const std::string &dum2,
+GeneralMatrix::multAndAdd(const ConstGeneralMatrix& a, [[maybe_unused]] const std::string& dum1,
+                          const ConstGeneralMatrix& b, [[maybe_unused]] const std::string& dum2,
                           double mult)
 {
   gemm("T", a, "T", b, mult, 1.0);
 }
 
 void
-GeneralMatrix::addOuter(const ConstVector &a, double mult)
+GeneralMatrix::addOuter(const ConstVector& a, double mult)
 {
   if (nrows() != ncols())
     throw SYLV_MES_EXCEPTION("Matrix is not square in GeneralMatrix::addOuter.");
@@ -145,7 +143,7 @@ GeneralMatrix::addOuter(const ConstVector &a, double mult)
   for (int i = 0; i < nrows(); i++)
     for (int j = i; j < nrows(); j++)
       {
-        double s = mult*a[i]*a[j];
+        double s = mult * a[i] * a[j];
         get(i, j) = get(i, j) + s;
         if (i != j)
           get(j, i) = get(j, i) + s;
@@ -153,25 +151,25 @@ GeneralMatrix::addOuter(const ConstVector &a, double mult)
 }
 
 void
-GeneralMatrix::multRight(const ConstGeneralMatrix &m)
+GeneralMatrix::multRight(const ConstGeneralMatrix& m)
 {
   gemm_partial_right("N", m, 1.0, 0.0);
 }
 
 void
-GeneralMatrix::multLeft(const ConstGeneralMatrix &m)
+GeneralMatrix::multLeft(const ConstGeneralMatrix& m)
 {
   gemm_partial_left("N", m, 1.0, 0.0);
 }
 
 void
-GeneralMatrix::multRightTrans(const ConstGeneralMatrix &m)
+GeneralMatrix::multRightTrans(const ConstGeneralMatrix& m)
 {
   gemm_partial_right("T", m, 1.0, 0.0);
 }
 
 void
-GeneralMatrix::multLeftTrans(const ConstGeneralMatrix &m)
+GeneralMatrix::multLeftTrans(const ConstGeneralMatrix& m)
 {
   gemm_partial_left("T", m, 1.0, 0.0);
 }
@@ -229,7 +227,7 @@ GeneralMatrix::mult(double a)
 
 // here we must be careful for ld
 void
-GeneralMatrix::add(double a, const ConstGeneralMatrix &m)
+GeneralMatrix::add(double a, const ConstGeneralMatrix& m)
 {
   if (m.nrows() != rows || m.ncols() != cols)
     throw SYLV_MES_EXCEPTION("Matrix has different size in GeneralMatrix::add.");
@@ -239,32 +237,32 @@ GeneralMatrix::add(double a, const ConstGeneralMatrix &m)
   else
     for (int i = 0; i < rows; i++)
       for (int j = 0; j < cols; j++)
-        get(i, j) += a*m.get(i, j);
+        get(i, j) += a * m.get(i, j);
 }
 
 void
-GeneralMatrix::add(double a, const ConstGeneralMatrix &m, [[maybe_unused]] const std::string &dum)
+GeneralMatrix::add(double a, const ConstGeneralMatrix& m, [[maybe_unused]] const std::string& dum)
 {
   if (m.nrows() != cols || m.ncols() != rows)
     throw SYLV_MES_EXCEPTION("Matrix has different size in GeneralMatrix::add.");
 
   for (int i = 0; i < rows; i++)
     for (int j = 0; j < cols; j++)
-      get(i, j) += a*m.get(j, i);
+      get(i, j) += a * m.get(j, i);
 }
 
 void
-GeneralMatrix::copy(const ConstGeneralMatrix &m, int ioff, int joff)
+GeneralMatrix::copy(const ConstGeneralMatrix& m, int ioff, int joff)
 {
   for (int i = 0; i < rows; i++)
     for (int j = 0; j < cols; j++)
-      get(i, j) = m.get(i+ioff, j+joff);
+      get(i, j) = m.get(i + ioff, j + joff);
 }
 
 void
-GeneralMatrix::gemm(const std::string &transa, const ConstGeneralMatrix &a,
-                    const std::string &transb, const ConstGeneralMatrix &b,
-                    double alpha, double beta)
+GeneralMatrix::gemm(const std::string& transa, const ConstGeneralMatrix& a,
+                    const std::string& transb, const ConstGeneralMatrix& b, double alpha,
+                    double beta)
 {
   int opa_rows = a.nrows();
   int opa_cols = a.ncols();
@@ -281,9 +279,7 @@ GeneralMatrix::gemm(const std::string &transa, const ConstGeneralMatrix &a,
       opb_cols = b.nrows();
     }
 
-  if (opa_rows != nrows()
-      || opb_cols != ncols()
-      || opa_cols != opb_rows)
+  if (opa_rows != nrows() || opb_cols != ncols() || opa_cols != opb_rows)
     throw SYLV_MES_EXCEPTION("Wrong dimensions for matrix multiplication.");
 
   blas_int m = opa_rows;
@@ -293,9 +289,9 @@ GeneralMatrix::gemm(const std::string &transa, const ConstGeneralMatrix &a,
   blas_int ldb = b.ld;
   blas_int ldc = ld;
   if (lda > 0 && ldb > 0 && ldc > 0)
-    dgemm(transa.c_str(), transb.c_str(), &m, &n, &k, &alpha, a.data.base(), &lda,
-          b.data.base(), &ldb, &beta, data.base(), &ldc);
-  else if (nrows()*ncols() > 0)
+    dgemm(transa.c_str(), transb.c_str(), &m, &n, &k, &alpha, a.data.base(), &lda, b.data.base(),
+          &ldb, &beta, data.base(), &ldc);
+  else if (nrows() * ncols() > 0)
     {
       if (beta == 0.0)
         zeros();
@@ -305,70 +301,73 @@ GeneralMatrix::gemm(const std::string &transa, const ConstGeneralMatrix &a,
 }
 
 void
-GeneralMatrix::gemm_partial_left(const std::string &trans, const ConstGeneralMatrix &m,
+GeneralMatrix::gemm_partial_left(const std::string& trans, const ConstGeneralMatrix& m,
                                  double alpha, double beta)
 {
   int icol;
   for (icol = 0; icol + md_length < cols; icol += md_length)
     {
-      GeneralMatrix incopy(const_cast<const GeneralMatrix &>(*this), 0, icol, rows, md_length);
+      GeneralMatrix incopy(const_cast<const GeneralMatrix&>(*this), 0, icol, rows, md_length);
       GeneralMatrix inplace(*this, 0, icol, rows, md_length);
       inplace.gemm(trans, m, "N", ConstGeneralMatrix(incopy), alpha, beta);
     }
   if (cols > icol)
     {
-      GeneralMatrix incopy(const_cast<const GeneralMatrix &>(*this), 0, icol, rows, cols - icol);
+      GeneralMatrix incopy(const_cast<const GeneralMatrix&>(*this), 0, icol, rows, cols - icol);
       GeneralMatrix inplace(*this, 0, icol, rows, cols - icol);
       inplace.gemm(trans, m, "N", ConstGeneralMatrix(incopy), alpha, beta);
     }
 }
 
 void
-GeneralMatrix::gemm_partial_right(const std::string &trans, const ConstGeneralMatrix &m,
+GeneralMatrix::gemm_partial_right(const std::string& trans, const ConstGeneralMatrix& m,
                                   double alpha, double beta)
 {
   int irow;
   for (irow = 0; irow + md_length < rows; irow += md_length)
     {
-      GeneralMatrix incopy(const_cast<const GeneralMatrix &>(*this), irow, 0, md_length, cols);
+      GeneralMatrix incopy(const_cast<const GeneralMatrix&>(*this), irow, 0, md_length, cols);
       GeneralMatrix inplace(*this, irow, 0, md_length, cols);
       inplace.gemm("N", ConstGeneralMatrix(incopy), trans, m, alpha, beta);
     }
   if (rows > irow)
     {
-      GeneralMatrix incopy(const_cast<const GeneralMatrix &>(*this), irow, 0, rows - irow, cols);
+      GeneralMatrix incopy(const_cast<const GeneralMatrix&>(*this), irow, 0, rows - irow, cols);
       GeneralMatrix inplace(*this, irow, 0, rows - irow, cols);
       inplace.gemm("N", ConstGeneralMatrix(incopy), trans, m, alpha, beta);
     }
 }
 
-ConstGeneralMatrix::ConstGeneralMatrix(const GeneralMatrix &m, int i, int j, int nrows, int ncols)
-  : data(m.getData(), j*m.getLD()+i, (ncols-1)*m.getLD()+nrows), rows(nrows), cols(ncols), ld(m.getLD())
+ConstGeneralMatrix::ConstGeneralMatrix(const GeneralMatrix& m, int i, int j, int nrows, int ncols) :
+    data(m.getData(), j * m.getLD() + i, (ncols - 1) * m.getLD() + nrows), rows(nrows), cols(ncols),
+    ld(m.getLD())
 {
   // FIXME: check that the submatrix is fully in the matrix
 }
 
-ConstGeneralMatrix::ConstGeneralMatrix(const ConstGeneralMatrix &m, int i, int j, int nrows, int ncols)
-  : data(m.getData(), j*m.getLD()+i, (ncols-1)*m.getLD()+nrows), rows(nrows), cols(ncols), ld(m.getLD())
+ConstGeneralMatrix::ConstGeneralMatrix(const ConstGeneralMatrix& m, int i, int j, int nrows,
+                                       int ncols) :
+    data(m.getData(), j * m.getLD() + i, (ncols - 1) * m.getLD() + nrows),
+    rows(nrows), cols(ncols), ld(m.getLD())
 {
   // FIXME: check that the submatrix is fully in the matrix
 }
 
-ConstGeneralMatrix::ConstGeneralMatrix(const GeneralMatrix &m)
-  : data(m.data), rows(m.rows), cols(m.cols), ld(m.ld)
+ConstGeneralMatrix::ConstGeneralMatrix(const GeneralMatrix& m) :
+    data(m.data), rows(m.rows), cols(m.cols), ld(m.ld)
 {
 }
 
 ConstVector
 ConstGeneralMatrix::getRow(int row) const
 {
-  return ConstVector{data, row, ld, cols};
+  return ConstVector {data, row, ld, cols};
 }
 
 ConstVector
 ConstGeneralMatrix::getCol(int col) const
 {
-  return ConstVector{data, ld*col, rows};
+  return ConstVector {data, ld * col, rows};
 }
 
 double
@@ -396,7 +395,7 @@ ConstGeneralMatrix::getNorm1() const
 }
 
 void
-ConstGeneralMatrix::multVec(double a, Vector &x, double b, const ConstVector &d) const
+ConstGeneralMatrix::multVec(double a, Vector& x, double b, const ConstVector& d) const
 {
   if (x.length() != rows || cols != d.length())
     throw SYLV_MES_EXCEPTION("Wrong dimensions for vector multiply.");
@@ -409,15 +408,12 @@ ConstGeneralMatrix::multVec(double a, Vector &x, double b, const ConstVector &d)
       blas_int incx = d.skip();
       double beta = a;
       blas_int incy = x.skip();
-      dgemv("N", &mm, &nn, &alpha, data.base(), &lda, d.base(), &incx,
-            &beta, x.base(), &incy);
+      dgemv("N", &mm, &nn, &alpha, data.base(), &lda, d.base(), &incx, &beta, x.base(), &incy);
     }
-
 }
 
 void
-ConstGeneralMatrix::multVecTrans(double a, Vector &x, double b,
-                                 const ConstVector &d) const
+ConstGeneralMatrix::multVecTrans(double a, Vector& x, double b, const ConstVector& d) const
 {
   if (x.length() != cols || rows != d.length())
     throw SYLV_MES_EXCEPTION("Wrong dimensions for vector multiply.");
@@ -430,14 +426,14 @@ ConstGeneralMatrix::multVecTrans(double a, Vector &x, double b,
       blas_int incx = d.skip();
       double beta = a;
       blas_int incy = x.skip();
-      dgemv("T", &mm, &nn, &alpha, data.base(), &lda, d.base(), &incx,
-            &beta, x.base(), &incy);
+      dgemv("T", &mm, &nn, &alpha, data.base(), &lda, d.base(), &incx, &beta, x.base(), &incy);
     }
 }
 
 /* m = inv(this)*m */
 void
-ConstGeneralMatrix::multInvLeft(const std::string &trans, int mrows, int mcols, int mld, double *d) const
+ConstGeneralMatrix::multInvLeft(const std::string& trans, int mrows, int mcols, int mld,
+                                double* d) const
 {
   if (rows != cols)
     throw SYLV_MES_EXCEPTION("The matrix is not square for inversion.");
@@ -451,28 +447,27 @@ ConstGeneralMatrix::multInvLeft(const std::string &trans, int mrows, int mcols,
       lapack_int info;
       lapack_int rows2 = rows, mcols2 = mcols, mld2 = mld, lda = inv.ld;
       dgetrf(&rows2, &rows2, inv.getData().base(), &lda, ipiv.get(), &info);
-      dgetrs(trans.c_str(), &rows2, &mcols2, inv.base(), &lda, ipiv.get(), d,
-             &mld2, &info);
+      dgetrs(trans.c_str(), &rows2, &mcols2, inv.base(), &lda, ipiv.get(), d, &mld2, &info);
     }
 }
 
 /* m = inv(this)*m */
 void
-ConstGeneralMatrix::multInvLeft(GeneralMatrix &m) const
+ConstGeneralMatrix::multInvLeft(GeneralMatrix& m) const
 {
   multInvLeft("N", m.nrows(), m.ncols(), m.getLD(), m.getData().base());
 }
 
 /* m = inv(this')*m */
 void
-ConstGeneralMatrix::multInvLeftTrans(GeneralMatrix &m) const
+ConstGeneralMatrix::multInvLeftTrans(GeneralMatrix& m) const
 {
   multInvLeft("T", m.nrows(), m.ncols(), m.getLD(), m.getData().base());
 }
 
 /* d = inv(this)*d */
 void
-ConstGeneralMatrix::multInvLeft(Vector &d) const
+ConstGeneralMatrix::multInvLeft(Vector& d) const
 {
   if (d.skip() != 1)
     throw SYLV_MES_EXCEPTION("Skip≠1 not implemented in ConstGeneralMatrix::multInvLeft(Vector&)");
@@ -482,7 +477,7 @@ ConstGeneralMatrix::multInvLeft(Vector &d) const
 
 /* d = inv(this')*d */
 void
-ConstGeneralMatrix::multInvLeftTrans(Vector &d) const
+ConstGeneralMatrix::multInvLeftTrans(Vector& d) const
 {
   if (d.skip() != 1)
     throw SYLV_MES_EXCEPTION("Skip≠1 not implemented in ConstGeneralMatrix::multInvLeft(Vector&)");
@@ -517,8 +512,7 @@ ConstGeneralMatrix::print() const
   std::cout << "rows=" << rows << ", cols=" << cols << std::endl;
   for (int i = 0; i < rows; i++)
     {
-      std::cout << "row " << i << ':' << std::endl
-                << std::setprecision(3);
+      std::cout << "row " << i << ':' << std::endl << std::setprecision(3);
       for (int j = 0; j < cols; j++)
         std::cout << std::setw(6) << get(i, j) << ' ';
       std::cout << std::endl;
@@ -527,7 +521,7 @@ ConstGeneralMatrix::print() const
 }
 
 void
-SVDDecomp::construct(const GeneralMatrix &A)
+SVDDecomp::construct(const GeneralMatrix& A)
 {
   // quick exit if empty matrix
   if (minmn == 0)
@@ -543,26 +537,24 @@ SVDDecomp::construct(const GeneralMatrix &A)
 
   lapack_int m = AA.nrows();
   lapack_int n = AA.ncols();
-  double *a = AA.base();
+  double* a = AA.base();
   lapack_int lda = AA.getLD();
-  double *s = sigma.base();
-  double *u = U.base();
+  double* s = sigma.base();
+  double* u = U.base();
   lapack_int ldu = U.getLD();
-  double *vt = VT.base();
+  double* vt = VT.base();
   lapack_int ldvt = VT.getLD();
   double tmpwork;
   lapack_int lwork = -1;
   lapack_int info;
 
-  auto iwork = std::make_unique<lapack_int[]>(8*minmn);
+  auto iwork = std::make_unique<lapack_int[]>(8 * minmn);
   // query for optimal lwork
-  dgesdd("A", &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, &tmpwork,
-         &lwork, iwork.get(), &info);
+  dgesdd("A", &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, &tmpwork, &lwork, iwork.get(), &info);
   lwork = static_cast<lapack_int>(tmpwork);
   Vector work(lwork);
   // do the decomposition
-  dgesdd("A", &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, work.base(),
-         &lwork, iwork.get(), &info);
+  dgesdd("A", &m, &n, a, &lda, s, u, &ldu, vt, &ldvt, work.base(), &lwork, iwork.get(), &info);
   if (info < 0)
     throw SYLV_MES_EXCEPTION("Internal error in SVDDecomp constructor");
   if (info == 0)
@@ -570,7 +562,7 @@ SVDDecomp::construct(const GeneralMatrix &A)
 }
 
 void
-SVDDecomp::solve(const ConstGeneralMatrix &B, GeneralMatrix &X) const
+SVDDecomp::solve(const ConstGeneralMatrix& B, GeneralMatrix& X) const
 {
   if (B.nrows() != U.nrows())
     throw SYLV_MES_EXCEPTION("Incompatible number of rows ");
@@ -581,20 +573,20 @@ SVDDecomp::solve(const ConstGeneralMatrix &B, GeneralMatrix &X) const
 
   // determine nz=number of zeros in the end of sigma
   int nz = 0;
-  while (nz < minmn && sigma[minmn-1-nz] < rcond*sigma[0])
+  while (nz < minmn && sigma[minmn - 1 - nz] < rcond * sigma[0])
     nz++;
   // take relevant B for sigma inversion
   int m = U.nrows();
   int n = VT.ncols();
-  GeneralMatrix Bprime(transpose(U) * B, m-minmn, 0, minmn-nz, B.ncols());
+  GeneralMatrix Bprime(transpose(U) * B, m - minmn, 0, minmn - nz, B.ncols());
   // solve sigma
-  for (int i = 0; i < minmn-nz; i++)
-    Bprime.getRow(i).mult(1.0/sigma[i]);
+  for (int i = 0; i < minmn - nz; i++)
+    Bprime.getRow(i).mult(1.0 / sigma[i]);
   // solve VT
   X.zeros();
   //- copy Bprime to right place of X
-  for (int i = 0; i < minmn-nz; i++)
-    X.getRow(n-minmn+i) = Bprime.getRow(i);
+  for (int i = 0; i < minmn - nz; i++)
+    X.getRow(n - minmn + i) = Bprime.getRow(i);
   //- multiply with VT
   X.multLeftTrans(VT);
 }
diff --git a/mex/sources/libkorder/sylv/GeneralMatrix.hh b/mex/sources/libkorder/sylv/GeneralMatrix.hh
index 61dbeec2610455682017ec59b4d69c2c8b366b29..a9168c51a6aa7f2cbc0195694076f8efff9953fc 100644
--- a/mex/sources/libkorder/sylv/GeneralMatrix.hh
+++ b/mex/sources/libkorder/sylv/GeneralMatrix.hh
@@ -21,36 +21,36 @@
 #ifndef GENERAL_MATRIX_H
 #define GENERAL_MATRIX_H
 
-#include "Vector.hh"
 #include "SylvException.hh"
+#include "Vector.hh"
 
 #include <algorithm>
 #include <memory>
-#include <utility>
 #include <string>
+#include <utility>
 
 template<class T>
 class TransposedMatrix
 {
   friend class GeneralMatrix;
   template<class T2>
-  friend GeneralMatrix operator*(const ConstGeneralMatrix &a, const TransposedMatrix<T2> &b);
+  friend GeneralMatrix operator*(const ConstGeneralMatrix& a, const TransposedMatrix<T2>& b);
   template<class T2>
-  friend GeneralMatrix operator*(const TransposedMatrix<T2> &a, const ConstGeneralMatrix &b);
+  friend GeneralMatrix operator*(const TransposedMatrix<T2>& a, const ConstGeneralMatrix& b);
   template<class T1, class T2>
-  friend GeneralMatrix operator*(const TransposedMatrix<T1> &a, const TransposedMatrix<T2> &b);
+  friend GeneralMatrix operator*(const TransposedMatrix<T1>& a, const TransposedMatrix<T2>& b);
+
 private:
-  T &orig;
+  T& orig;
+
 public:
-  TransposedMatrix(T &orig_arg) : orig{orig_arg}
-  {
-  };
+  TransposedMatrix(T& orig_arg) : orig {orig_arg} {};
 };
 
 // Syntactic sugar for representing a transposed matrix
 template<class T>
 TransposedMatrix<T>
-transpose(T &m)
+transpose(T& m)
 {
   return TransposedMatrix<T>(m);
 }
@@ -60,50 +60,51 @@ class GeneralMatrix;
 class ConstGeneralMatrix
 {
   friend class GeneralMatrix;
-  friend GeneralMatrix operator*(const ConstGeneralMatrix &a, const ConstGeneralMatrix &b);
+  friend GeneralMatrix operator*(const ConstGeneralMatrix& a, const ConstGeneralMatrix& b);
   template<class T>
-  friend GeneralMatrix operator*(const ConstGeneralMatrix &a, const TransposedMatrix<T> &b);
+  friend GeneralMatrix operator*(const ConstGeneralMatrix& a, const TransposedMatrix<T>& b);
   template<class T>
-  friend GeneralMatrix operator*(const TransposedMatrix<T> &a, const ConstGeneralMatrix &b);
+  friend GeneralMatrix operator*(const TransposedMatrix<T>& a, const ConstGeneralMatrix& b);
   template<class T1, class T2>
-  friend GeneralMatrix operator*(const TransposedMatrix<T1> &a, const TransposedMatrix<T2> &b);
+  friend GeneralMatrix operator*(const TransposedMatrix<T1>& a, const TransposedMatrix<T2>& b);
+
 protected:
   ConstVector data; // Has unit-stride
   int rows;
   int cols;
   int ld;
+
 public:
-  ConstGeneralMatrix(ConstVector d, int m, int n)
-    : data(std::move(d)), rows(m), cols(n), ld(m)
+  ConstGeneralMatrix(ConstVector d, int m, int n) : data(std::move(d)), rows(m), cols(n), ld(m)
   {
     if (data.skip() > 1)
       throw SYLV_MES_EXCEPTION("Vector must have unit-stride");
-    if (data.length() < m*n)
+    if (data.length() < m * n)
       throw SYLV_MES_EXCEPTION("Vector is too small");
   }
-  ConstGeneralMatrix(const ConstGeneralMatrix &m) = default;
-  ConstGeneralMatrix(ConstGeneralMatrix &&m) = default;
+  ConstGeneralMatrix(const ConstGeneralMatrix& m) = default;
+  ConstGeneralMatrix(ConstGeneralMatrix&& m) = default;
   // Implicit conversion from GeneralMatrix is ok, since it's cheap
-  ConstGeneralMatrix(const GeneralMatrix &m);
+  ConstGeneralMatrix(const GeneralMatrix& m);
   // Create submatrix (with data sharing)
-  ConstGeneralMatrix(const GeneralMatrix &m, int i, int j, int nrows, int ncols);
+  ConstGeneralMatrix(const GeneralMatrix& m, int i, int j, int nrows, int ncols);
   // Create submatrix (with data sharing)
-  ConstGeneralMatrix(const ConstGeneralMatrix &m, int i, int j, int nrows, int ncols);
+  ConstGeneralMatrix(const ConstGeneralMatrix& m, int i, int j, int nrows, int ncols);
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-  explicit ConstGeneralMatrix(const mxArray *p)
-    : data(p), rows{static_cast<int>(mxGetM(p))}, cols{static_cast<int>(mxGetN(p))}, ld{rows}
+  explicit ConstGeneralMatrix(const mxArray* p) :
+      data(p), rows {static_cast<int>(mxGetM(p))}, cols {static_cast<int>(mxGetN(p))}, ld {rows}
   {
   }
 #endif
   virtual ~ConstGeneralMatrix() = default;
 
-  ConstGeneralMatrix &operator=(const ConstGeneralMatrix &v) = delete;
-  ConstGeneralMatrix &operator=(ConstGeneralMatrix &&v) = delete;
+  ConstGeneralMatrix& operator=(const ConstGeneralMatrix& v) = delete;
+  ConstGeneralMatrix& operator=(ConstGeneralMatrix&& v) = delete;
 
-  const double &
+  const double&
   get(int i, int j) const
   {
-    return data[j*ld+i];
+    return data[j * ld + i];
   }
   int
   nrows() const
@@ -120,12 +121,12 @@ public:
   {
     return ld;
   }
-  const double *
+  const double*
   base() const
   {
     return data.base();
   }
-  const ConstVector &
+  const ConstVector&
   getData() const
   {
     return data;
@@ -136,91 +137,92 @@ public:
   double getNormInf() const;
   double getNorm1() const;
   /* x = scalar(a)*x + scalar(b)*this*d */
-  void multVec(double a, Vector &x, double b, const ConstVector &d) const;
+  void multVec(double a, Vector& x, double b, const ConstVector& d) const;
   /* x = scalar(a)*x + scalar(b)*this'*d */
-  void multVecTrans(double a, Vector &x, double b, const ConstVector &d) const;
+  void multVecTrans(double a, Vector& x, double b, const ConstVector& d) const;
   /* x = x + this*d */
   void
-  multaVec(Vector &x, const ConstVector &d) const
+  multaVec(Vector& x, const ConstVector& d) const
   {
     multVec(1.0, x, 1.0, d);
   }
   /* x = x + this'*d */
   void
-  multaVecTrans(Vector &x, const ConstVector &d) const
+  multaVecTrans(Vector& x, const ConstVector& d) const
   {
     multVecTrans(1.0, x, 1.0, d);
   }
   /* x = x - this*d */
   void
-  multsVec(Vector &x, const ConstVector &d) const
+  multsVec(Vector& x, const ConstVector& d) const
   {
     multVec(1.0, x, -1.0, d);
   }
   /* x = x - this'*d */
   void
-  multsVecTrans(Vector &x, const ConstVector &d) const
+  multsVecTrans(Vector& x, const ConstVector& d) const
   {
     multVecTrans(1.0, x, -1.0, d);
   }
   /* m = inv(this)*m */
-  void multInvLeft(GeneralMatrix &m) const;
+  void multInvLeft(GeneralMatrix& m) const;
   /* m = inv(this')*m */
-  void multInvLeftTrans(GeneralMatrix &m) const;
+  void multInvLeftTrans(GeneralMatrix& m) const;
   /* d = inv(this)*d */
-  void multInvLeft(Vector &d) const;
+  void multInvLeft(Vector& d) const;
   /* d = inv(this')*d */
-  void multInvLeftTrans(Vector &d) const;
+  void multInvLeftTrans(Vector& d) const;
 
   bool isFinite() const;
   /** Returns true of the matrix is exactly zero. */
   bool isZero() const;
 
   virtual void print() const;
+
 protected:
-  void multInvLeft(const std::string &trans, int mrows, int mcols, int mld, double *d) const;
+  void multInvLeft(const std::string& trans, int mrows, int mcols, int mld, double* d) const;
 };
 
 class GeneralMatrix
 {
   friend class ConstGeneralMatrix;
-  friend GeneralMatrix operator*(const ConstGeneralMatrix &a, const ConstGeneralMatrix &b);
+  friend GeneralMatrix operator*(const ConstGeneralMatrix& a, const ConstGeneralMatrix& b);
   template<class T>
-  friend GeneralMatrix operator*(const ConstGeneralMatrix &a, const TransposedMatrix<T> &b);
+  friend GeneralMatrix operator*(const ConstGeneralMatrix& a, const TransposedMatrix<T>& b);
   template<class T>
-  friend GeneralMatrix operator*(const TransposedMatrix<T> &a, const ConstGeneralMatrix &b);
+  friend GeneralMatrix operator*(const TransposedMatrix<T>& a, const ConstGeneralMatrix& b);
   template<class T1, class T2>
-  friend GeneralMatrix operator*(const TransposedMatrix<T1> &a, const TransposedMatrix<T2> &b);
+  friend GeneralMatrix operator*(const TransposedMatrix<T1>& a, const TransposedMatrix<T2>& b);
+
 protected:
   Vector data; // Has unit-stride
   int rows;
   int cols;
   int ld;
+
 public:
-  GeneralMatrix(int m, int n)
-    : data(m*n), rows(m), cols(n), ld(m)
+  GeneralMatrix(int m, int n) : data(m * n), rows(m), cols(n), ld(m)
   {
   }
-  GeneralMatrix(Vector d, int m, int n)
-    : data(std::move(d)), rows(m), cols(n), ld(m)
+  GeneralMatrix(Vector d, int m, int n) : data(std::move(d)), rows(m), cols(n), ld(m)
   {
     if (data.skip() > 1)
       throw SYLV_MES_EXCEPTION("Vector must have unit-stride");
-    if (data.length() < m*n)
+    if (data.length() < m * n)
       throw SYLV_MES_EXCEPTION("Vector is too small");
   }
 
   /* The copies will have ld==rows, for memory efficiency (hence we do not use
      the default copy constructor) */
-  GeneralMatrix(const GeneralMatrix &m);
+  GeneralMatrix(const GeneralMatrix& m);
   // We don't want implict conversion from ConstGeneralMatrix, since it's expensive
-  explicit GeneralMatrix(const ConstGeneralMatrix &m);
+  explicit GeneralMatrix(const ConstGeneralMatrix& m);
 
-  GeneralMatrix(GeneralMatrix &&m) = default;
+  GeneralMatrix(GeneralMatrix&& m) = default;
 
   template<class T>
-  explicit GeneralMatrix(const TransposedMatrix<T> &m)
-    : data(m.orig.rows*m.orig.cols), rows(m.orig.cols), cols(m.orig.rows), ld(rows)
+  explicit GeneralMatrix(const TransposedMatrix<T>& m) :
+      data(m.orig.rows * m.orig.cols), rows(m.orig.cols), cols(m.orig.rows), ld(rows)
   {
     for (int i = 0; i < rows; i++)
       for (int j = 0; j < cols; j++)
@@ -228,31 +230,31 @@ public:
   }
 
   // Create submatrix (with data copy)
-  GeneralMatrix(const GeneralMatrix &m, int i, int j, int nrows, int ncols);
+  GeneralMatrix(const GeneralMatrix& m, int i, int j, int nrows, int ncols);
   // Create submatrix (with data sharing)
-  GeneralMatrix(GeneralMatrix &m, int i, int j, int nrows, int ncols);
+  GeneralMatrix(GeneralMatrix& m, int i, int j, int nrows, int ncols);
 
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-  explicit GeneralMatrix(mxArray *p)
-    : data(p), rows{static_cast<int>(mxGetM(p))}, cols{static_cast<int>(mxGetN(p))}, ld{rows}
+  explicit GeneralMatrix(mxArray* p) :
+      data(p), rows {static_cast<int>(mxGetM(p))}, cols {static_cast<int>(mxGetN(p))}, ld {rows}
   {
   }
 #endif
 
   virtual ~GeneralMatrix() = default;
-  GeneralMatrix &operator=(const GeneralMatrix &m) = default;
-  GeneralMatrix &operator=(GeneralMatrix &&m) = default;
-  GeneralMatrix &operator=(const ConstGeneralMatrix &m);
+  GeneralMatrix& operator=(const GeneralMatrix& m) = default;
+  GeneralMatrix& operator=(GeneralMatrix&& m) = default;
+  GeneralMatrix& operator=(const ConstGeneralMatrix& m);
 
-  const double &
+  const double&
   get(int i, int j) const
   {
-    return data[j*ld+i];
+    return data[j * ld + i];
   }
-  double &
+  double&
   get(int i, int j)
   {
-    return data[j*ld+i];
+    return data[j * ld + i];
   }
   int
   nrows() const
@@ -269,17 +271,17 @@ public:
   {
     return ld;
   }
-  double *
+  double*
   base()
   {
     return data.base();
   }
-  const double *
+  const double*
   base() const
   {
     return data.base();
   }
-  Vector &
+  Vector&
   getData()
   {
     return data;
@@ -306,139 +308,137 @@ public:
   }
 
   /* place matrix m to the position (i,j) */
-  void place(const ConstGeneralMatrix &m, int i, int j);
+  void place(const ConstGeneralMatrix& m, int i, int j);
   void
-  place(const GeneralMatrix &m, int i, int j)
+  place(const GeneralMatrix& m, int i, int j)
   {
     place(ConstGeneralMatrix(m), i, j);
   }
 
   // this = a·b
-  void mult(const ConstGeneralMatrix &a, const ConstGeneralMatrix &b);
+  void mult(const ConstGeneralMatrix& a, const ConstGeneralMatrix& b);
   void
-  mult(const GeneralMatrix &a, const GeneralMatrix &b)
+  mult(const GeneralMatrix& a, const GeneralMatrix& b)
   {
     mult(ConstGeneralMatrix(a), ConstGeneralMatrix(b));
   }
 
   // this = this + scalar·a·b
-  void multAndAdd(const ConstGeneralMatrix &a, const ConstGeneralMatrix &b,
-                  double mult = 1.0);
+  void multAndAdd(const ConstGeneralMatrix& a, const ConstGeneralMatrix& b, double mult = 1.0);
   void
-  multAndAdd(const GeneralMatrix &a, const GeneralMatrix &b,
-             double mult = 1.0)
+  multAndAdd(const GeneralMatrix& a, const GeneralMatrix& b, double mult = 1.0)
   {
     multAndAdd(ConstGeneralMatrix(a), ConstGeneralMatrix(b), mult);
   }
 
   // this = this + scalar·a·bᵀ
-  void multAndAdd(const ConstGeneralMatrix &a, const ConstGeneralMatrix &b,
-                  const std::string &dum, double mult = 1.0);
+  void multAndAdd(const ConstGeneralMatrix& a, const ConstGeneralMatrix& b, const std::string& dum,
+                  double mult = 1.0);
   void
-  multAndAdd(const GeneralMatrix &a, const GeneralMatrix &b,
-             const std::string &dum, double mult = 1.0)
+  multAndAdd(const GeneralMatrix& a, const GeneralMatrix& b, const std::string& dum,
+             double mult = 1.0)
   {
     multAndAdd(ConstGeneralMatrix(a), ConstGeneralMatrix(b), dum, mult);
   }
 
   // this = this + scalar·aᵀ·b
-  void multAndAdd(const ConstGeneralMatrix &a, const std::string &dum, const ConstGeneralMatrix &b,
+  void multAndAdd(const ConstGeneralMatrix& a, const std::string& dum, const ConstGeneralMatrix& b,
                   double mult = 1.0);
   void
-  multAndAdd(const GeneralMatrix &a, const std::string &dum, const GeneralMatrix &b,
+  multAndAdd(const GeneralMatrix& a, const std::string& dum, const GeneralMatrix& b,
              double mult = 1.0)
   {
     multAndAdd(ConstGeneralMatrix(a), dum, ConstGeneralMatrix(b), mult);
   }
 
   // this = this + scalar·aᵀ·bᵀ
-  void multAndAdd(const ConstGeneralMatrix &a, const std::string &dum1,
-                  const ConstGeneralMatrix &b, const std::string &dum2, double mult = 1.0);
+  void multAndAdd(const ConstGeneralMatrix& a, const std::string& dum1, const ConstGeneralMatrix& b,
+                  const std::string& dum2, double mult = 1.0);
   void
-  multAndAdd(const GeneralMatrix &a, const std::string &dum1,
-             const GeneralMatrix &b, const std::string &dum2, double mult = 1.0)
+  multAndAdd(const GeneralMatrix& a, const std::string& dum1, const GeneralMatrix& b,
+             const std::string& dum2, double mult = 1.0)
   {
     multAndAdd(ConstGeneralMatrix(a), dum1, ConstGeneralMatrix(b), dum2, mult);
   }
 
   // this = this + scalar·a·aᵀ
-  void addOuter(const ConstVector &a, double mult = 1.0);
+  void addOuter(const ConstVector& a, double mult = 1.0);
   void
-  addOuter(const Vector &a, double mult = 1.0)
+  addOuter(const Vector& a, double mult = 1.0)
   {
     addOuter(ConstVector(a), mult);
   }
 
   // this = this·m
-  void multRight(const ConstGeneralMatrix &m);
+  void multRight(const ConstGeneralMatrix& m);
   void
-  multRight(const GeneralMatrix &m)
+  multRight(const GeneralMatrix& m)
   {
     multRight(ConstGeneralMatrix(m));
   }
 
   // this = m·this
-  void multLeft(const ConstGeneralMatrix &m);
+  void multLeft(const ConstGeneralMatrix& m);
   void
-  multLeft(const GeneralMatrix &m)
+  multLeft(const GeneralMatrix& m)
   {
     multLeft(ConstGeneralMatrix(m));
   }
 
   // this = this·mᵀ
-  void multRightTrans(const ConstGeneralMatrix &m);
+  void multRightTrans(const ConstGeneralMatrix& m);
   void
-  multRightTrans(const GeneralMatrix &m)
+  multRightTrans(const GeneralMatrix& m)
   {
     multRightTrans(ConstGeneralMatrix(m));
   }
 
   // this = mᵀ·this
-  void multLeftTrans(const ConstGeneralMatrix &m);
+  void multLeftTrans(const ConstGeneralMatrix& m);
   void
-  multLeftTrans(const GeneralMatrix &m)
+  multLeftTrans(const GeneralMatrix& m)
   {
     multLeftTrans(ConstGeneralMatrix(m));
   }
 
   // x = scalar(a)·x + scalar(b)·this·d
   void
-  multVec(double a, Vector &x, double b, const ConstVector &d) const
+  multVec(double a, Vector& x, double b, const ConstVector& d) const
   {
     ConstGeneralMatrix(*this).multVec(a, x, b, d);
   }
 
   // x = scalar(a)·x + scalar(b)·thisᵀ·d
   void
-  multVecTrans(double a, Vector &x, double b, const ConstVector &d) const
+  multVecTrans(double a, Vector& x, double b, const ConstVector& d) const
   {
     ConstGeneralMatrix(*this).multVecTrans(a, x, b, d);
   }
 
   // x = x + this·d
   void
-  multaVec(Vector &x, const ConstVector &d) const
+  multaVec(Vector& x, const ConstVector& d) const
   {
     ConstGeneralMatrix(*this).multaVec(x, d);
   }
 
   // x = x + thisᵀ·d */
   void
-  multaVecTrans(Vector &x, const ConstVector &d) const
+  multaVecTrans(Vector& x, const ConstVector& d) const
   {
     ConstGeneralMatrix(*this).multaVecTrans(x, d);
   }
 
   // x = x - this·d
   void
-  multsVec(Vector &x, const ConstVector &d) const
+  multsVec(Vector& x, const ConstVector& d) const
   {
     ConstGeneralMatrix(*this).multsVec(x, d);
   }
 
   // x = x - thisᵀ·d
   void
-  multsVecTrans(Vector &x, const ConstVector &d) const
+  multsVecTrans(Vector& x, const ConstVector& d) const
   {
     ConstGeneralMatrix(*this).multsVecTrans(x, d);
   }
@@ -459,17 +459,17 @@ public:
   void mult(double a);
 
   // this = this + scalar·m
-  void add(double a, const ConstGeneralMatrix &m);
+  void add(double a, const ConstGeneralMatrix& m);
   void
-  add(double a, const GeneralMatrix &m)
+  add(double a, const GeneralMatrix& m)
   {
     add(a, ConstGeneralMatrix(m));
   }
 
   // this = this + scalar·mᵀ
-  void add(double a, const ConstGeneralMatrix &m, const std::string &dum);
+  void add(double a, const ConstGeneralMatrix& m, const std::string& dum);
   void
-  add(double a, const GeneralMatrix &m, const std::string &dum)
+  add(double a, const GeneralMatrix& m, const std::string& dum)
   {
     add(a, ConstGeneralMatrix(m), dum);
   }
@@ -491,42 +491,38 @@ public:
   {
     ConstGeneralMatrix(*this).print();
   }
+
 private:
-  void copy(const ConstGeneralMatrix &m, int ioff = 0, int joff = 0);
+  void copy(const ConstGeneralMatrix& m, int ioff = 0, int joff = 0);
   void
-  copy(const GeneralMatrix &m, int ioff = 0, int joff = 0)
+  copy(const GeneralMatrix& m, int ioff = 0, int joff = 0)
   {
     copy(ConstGeneralMatrix(m), ioff, joff);
   }
 
-  void gemm(const std::string &transa, const ConstGeneralMatrix &a,
-            const std::string &transb, const ConstGeneralMatrix &b,
-            double alpha, double beta);
+  void gemm(const std::string& transa, const ConstGeneralMatrix& a, const std::string& transb,
+            const ConstGeneralMatrix& b, double alpha, double beta);
   void
-  gemm(const std::string &transa, const GeneralMatrix &a,
-       const std::string &transb, const GeneralMatrix &b,
-       double alpha, double beta)
+  gemm(const std::string& transa, const GeneralMatrix& a, const std::string& transb,
+       const GeneralMatrix& b, double alpha, double beta)
   {
-    gemm(transa, ConstGeneralMatrix(a), transb, ConstGeneralMatrix(b),
-         alpha, beta);
+    gemm(transa, ConstGeneralMatrix(a), transb, ConstGeneralMatrix(b), alpha, beta);
   }
 
   /* this = this * op(m) (without whole copy of this) */
-  void gemm_partial_right(const std::string &trans, const ConstGeneralMatrix &m,
-                          double alpha, double beta);
+  void gemm_partial_right(const std::string& trans, const ConstGeneralMatrix& m, double alpha,
+                          double beta);
   void
-  gemm_partial_right(const std::string &trans, const GeneralMatrix &m,
-                     double alpha, double beta)
+  gemm_partial_right(const std::string& trans, const GeneralMatrix& m, double alpha, double beta)
   {
     gemm_partial_right(trans, ConstGeneralMatrix(m), alpha, beta);
   }
 
   // this = op(m)·this (without whole copy of ‘this’)
-  void gemm_partial_left(const std::string &trans, const ConstGeneralMatrix &m,
-                         double alpha, double beta);
+  void gemm_partial_left(const std::string& trans, const ConstGeneralMatrix& m, double alpha,
+                         double beta);
   void
-  gemm_partial_left(const std::string &trans, const GeneralMatrix &m,
-                    double alpha, double beta)
+  gemm_partial_left(const std::string& trans, const GeneralMatrix& m, double alpha, double beta)
   {
     gemm_partial_left(trans, ConstGeneralMatrix(m), alpha, beta);
   }
@@ -537,7 +533,7 @@ private:
 
 // Computes a·b
 inline GeneralMatrix
-operator*(const ConstGeneralMatrix &a, const ConstGeneralMatrix &b)
+operator*(const ConstGeneralMatrix& a, const ConstGeneralMatrix& b)
 {
   GeneralMatrix m(a.rows, b.cols);
   m.gemm("N", a, "N", b, 1.0, 0.0);
@@ -547,7 +543,7 @@ operator*(const ConstGeneralMatrix &a, const ConstGeneralMatrix &b)
 // Computes a·bᵀ
 template<class T>
 GeneralMatrix
-operator*(const ConstGeneralMatrix &a, const TransposedMatrix<T> &b)
+operator*(const ConstGeneralMatrix& a, const TransposedMatrix<T>& b)
 {
   GeneralMatrix m(a.rows, b.orig.rows);
   m.gemm("N", a, "T", b.orig, 1.0, 0.0);
@@ -557,7 +553,7 @@ operator*(const ConstGeneralMatrix &a, const TransposedMatrix<T> &b)
 // Computes aᵀ·b
 template<class T>
 GeneralMatrix
-operator*(const TransposedMatrix<T> &a, const ConstGeneralMatrix &b)
+operator*(const TransposedMatrix<T>& a, const ConstGeneralMatrix& b)
 {
   GeneralMatrix m(a.orig.cols, b.cols);
   m.gemm("T", a.orig, "N", b, 1.0, 0.0);
@@ -567,7 +563,7 @@ operator*(const TransposedMatrix<T> &a, const ConstGeneralMatrix &b)
 // Computes aᵀ·bᵀ
 template<class T1, class T2>
 GeneralMatrix
-operator*(const TransposedMatrix<T1> &a, const TransposedMatrix<T2> &b)
+operator*(const TransposedMatrix<T1>& a, const TransposedMatrix<T2>& b)
 {
   GeneralMatrix m(a.orig.cols, b.orig.rows);
   m.gemm("T", a.orig, "T", b.orig, 1.0, 0.0);
@@ -587,35 +583,34 @@ protected:
   GeneralMatrix VT;
   // Convered flag
   bool conv;
+
 public:
-  SVDDecomp(const GeneralMatrix &A)
-    : minmn(std::min<int>(A.nrows(), A.ncols())),
-      sigma(minmn),
-      U(A.nrows(), A.nrows()),
-      VT(A.ncols(), A.ncols()),
-      conv(false)
+  SVDDecomp(const GeneralMatrix& A) :
+      minmn(std::min<int>(A.nrows(), A.ncols())), sigma(minmn), U(A.nrows(), A.nrows()),
+      VT(A.ncols(), A.ncols()), conv(false)
   {
     construct(A);
   }
-  const GeneralMatrix &
+  const GeneralMatrix&
   getU() const
   {
     return U;
   }
-  const GeneralMatrix &
+  const GeneralMatrix&
   getVT() const
   {
     return VT;
   }
-  void solve(const ConstGeneralMatrix &B, GeneralMatrix &X) const;
+  void solve(const ConstGeneralMatrix& B, GeneralMatrix& X) const;
   void
-  solve(const ConstVector &b, Vector &x) const
+  solve(const ConstVector& b, Vector& x) const
   {
     GeneralMatrix xmat(x, x.length(), 1);
     solve(ConstGeneralMatrix(b, b.length(), 1), xmat);
   }
+
 private:
-  void construct(const GeneralMatrix &A);
+  void construct(const GeneralMatrix& A);
 };
 
 #endif /* GENERAL_MATRIX_H */
diff --git a/mex/sources/libkorder/sylv/GeneralSylvester.cc b/mex/sources/libkorder/sylv/GeneralSylvester.cc
index 89994de685e8ff519e9ea5310d103716e85d704b..785de3e274fcbb7e82ab4b75aada4b7d5ff0390b 100644
--- a/mex/sources/libkorder/sylv/GeneralSylvester.cc
+++ b/mex/sources/libkorder/sylv/GeneralSylvester.cc
@@ -19,58 +19,50 @@
  */
 
 #include "GeneralSylvester.hh"
+#include "IterativeSylvester.hh"
 #include "SchurDecomp.hh"
 #include "SylvException.hh"
 #include "TriangularSylvester.hh"
-#include "IterativeSylvester.hh"
 #include "int_power.hh"
 
 #include <ctime>
 
-GeneralSylvester::GeneralSylvester(int ord, int n, int m, int zero_cols,
-                                   const ConstVector &da, const ConstVector &db,
-                                   const ConstVector &dc, const ConstVector &dd,
-                                   const SylvParams &ps)
-  : pars(ps),
-    order(ord), a(Vector{da}, n),
-    b(Vector{db}, n, n-zero_cols), c(Vector{dc}, m), d(Vector{dd}, n, power(m, order)),
-    solved(false)
+GeneralSylvester::GeneralSylvester(int ord, int n, int m, int zero_cols, const ConstVector& da,
+                                   const ConstVector& db, const ConstVector& dc,
+                                   const ConstVector& dd, const SylvParams& ps) :
+    pars(ps),
+    order(ord), a(Vector {da}, n), b(Vector {db}, n, n - zero_cols), c(Vector {dc}, m),
+    d(Vector {dd}, n, power(m, order)), solved(false)
 {
   init();
 }
 
-GeneralSylvester::GeneralSylvester(int ord, int n, int m, int zero_cols,
-                                   const ConstVector &da, const ConstVector &db,
-                                   const ConstVector &dc, Vector &dd,
-                                   const SylvParams &ps)
-  : pars(ps),
-    order(ord), a(Vector{da}, n),
-    b(Vector{db}, n, n-zero_cols), c(Vector{dc}, m), d(dd, n, power(m, order)),
-    solved(false)
+GeneralSylvester::GeneralSylvester(int ord, int n, int m, int zero_cols, const ConstVector& da,
+                                   const ConstVector& db, const ConstVector& dc, Vector& dd,
+                                   const SylvParams& ps) :
+    pars(ps),
+    order(ord), a(Vector {da}, n), b(Vector {db}, n, n - zero_cols), c(Vector {dc}, m),
+    d(dd, n, power(m, order)), solved(false)
 {
   init();
 }
 
-GeneralSylvester::GeneralSylvester(int ord, int n, int m, int zero_cols,
-                                   const ConstVector &da, const ConstVector &db,
-                                   const ConstVector &dc, const ConstVector &dd,
-                                   bool alloc_for_check)
-  : pars(alloc_for_check),
-    order(ord), a(Vector{da}, n),
-    b(Vector{db}, n, n-zero_cols), c(Vector{dc}, m), d(Vector{dd}, n, power(m, order)),
-    solved(false)
+GeneralSylvester::GeneralSylvester(int ord, int n, int m, int zero_cols, const ConstVector& da,
+                                   const ConstVector& db, const ConstVector& dc,
+                                   const ConstVector& dd, bool alloc_for_check) :
+    pars(alloc_for_check),
+    order(ord), a(Vector {da}, n), b(Vector {db}, n, n - zero_cols), c(Vector {dc}, m),
+    d(Vector {dd}, n, power(m, order)), solved(false)
 {
   init();
 }
 
-GeneralSylvester::GeneralSylvester(int ord, int n, int m, int zero_cols,
-                                   const ConstVector &da, const ConstVector &db,
-                                   const ConstVector &dc, Vector &dd,
-                                   bool alloc_for_check)
-  : pars(alloc_for_check),
-    order(ord), a(Vector{da}, n),
-    b(Vector{db}, n, n-zero_cols), c(Vector{dc}, m), d(dd, n, power(m, order)),
-    solved(false)
+GeneralSylvester::GeneralSylvester(int ord, int n, int m, int zero_cols, const ConstVector& da,
+                                   const ConstVector& db, const ConstVector& dc, Vector& dd,
+                                   bool alloc_for_check) :
+    pars(alloc_for_check),
+    order(ord), a(Vector {da}, n), b(Vector {db}, n, n - zero_cols), c(Vector {dc}, m),
+    d(dd, n, power(m, order)), solved(false)
 {
   init();
 }
@@ -112,27 +104,27 @@ GeneralSylvester::solve()
   d.multLeftI(bdecomp->getQ());
   d.multRightKron(cdecomp->getInvQ(), order);
   clock_t end = clock();
-  pars.cpu_time = static_cast<double>(end-start)/CLOCKS_PER_SEC;
+  pars.cpu_time = static_cast<double>(end - start) / CLOCKS_PER_SEC;
 
   solved = true;
 }
 
 void
-GeneralSylvester::check(const ConstVector &ds)
+GeneralSylvester::check(const ConstVector& ds)
 {
   if (!solved)
     throw SYLV_MES_EXCEPTION("Cannot run check on system, which is not solved yet.");
 
   // calculate xcheck = A·X+B·X·⊗ⁱC−D
   SylvMatrix dcheck(d.nrows(), d.ncols());
-  dcheck.multLeft(b.nrows()-b.ncols(), b, d);
+  dcheck.multLeft(b.nrows() - b.ncols(), b, d);
   dcheck.multRightKron(c, order);
   dcheck.multAndAdd(a, d);
   dcheck.getData().add(-1.0, ds);
   // calculate relative norms
-  pars.mat_err1 = dcheck.getNorm1()/d.getNorm1();
-  pars.mat_errI = dcheck.getNormInf()/d.getNormInf();
-  pars.mat_errF = dcheck.getData().getNorm()/d.getData().getNorm();
-  pars.vec_err1 = dcheck.getData().getNorm1()/d.getData().getNorm1();
-  pars.vec_errI = dcheck.getData().getMax()/d.getData().getMax();
+  pars.mat_err1 = dcheck.getNorm1() / d.getNorm1();
+  pars.mat_errI = dcheck.getNormInf() / d.getNormInf();
+  pars.mat_errF = dcheck.getData().getNorm() / d.getData().getNorm();
+  pars.vec_err1 = dcheck.getData().getNorm1() / d.getData().getNorm1();
+  pars.vec_errI = dcheck.getData().getMax() / d.getData().getMax();
 }
diff --git a/mex/sources/libkorder/sylv/GeneralSylvester.hh b/mex/sources/libkorder/sylv/GeneralSylvester.hh
index 83d439cf9dd1859f9e163249a1638d534b53773f..cc935c69ced66503c8b3300c84e7eebb3b01ca21 100644
--- a/mex/sources/libkorder/sylv/GeneralSylvester.hh
+++ b/mex/sources/libkorder/sylv/GeneralSylvester.hh
@@ -21,8 +21,8 @@
 #ifndef GENERAL_SYLVESTER_H
 #define GENERAL_SYLVESTER_H
 
-#include "SylvMatrix.hh"
 #include "SimilarityDecomp.hh"
+#include "SylvMatrix.hh"
 #include "SylvesterSolver.hh"
 
 #include <memory>
@@ -39,25 +39,21 @@ class GeneralSylvester
   std::unique_ptr<SchurDecompZero> bdecomp;
   std::unique_ptr<SimilarityDecomp> cdecomp;
   std::unique_ptr<SylvesterSolver> sylv;
+
 public:
   // Construct with my copy of d
-  GeneralSylvester(int ord, int n, int m, int zero_cols,
-                   const ConstVector &da, const ConstVector &db,
-                   const ConstVector &dc, const ConstVector &dd,
-                   const SylvParams &ps);
-  GeneralSylvester(int ord, int n, int m, int zero_cols,
-                   const ConstVector &da, const ConstVector &db,
-                   const ConstVector &dc, const ConstVector &dd,
+  GeneralSylvester(int ord, int n, int m, int zero_cols, const ConstVector& da,
+                   const ConstVector& db, const ConstVector& dc, const ConstVector& dd,
+                   const SylvParams& ps);
+  GeneralSylvester(int ord, int n, int m, int zero_cols, const ConstVector& da,
+                   const ConstVector& db, const ConstVector& dc, const ConstVector& dd,
                    bool alloc_for_check = false);
   // Construct with provided storage for d
-  GeneralSylvester(int ord, int n, int m, int zero_cols,
-                   const ConstVector &da, const ConstVector &db,
-                   const ConstVector &dc, Vector &dd,
+  GeneralSylvester(int ord, int n, int m, int zero_cols, const ConstVector& da,
+                   const ConstVector& db, const ConstVector& dc, Vector& dd,
                    bool alloc_for_check = false);
-  GeneralSylvester(int ord, int n, int m, int zero_cols,
-                   const ConstVector &da, const ConstVector &db,
-                   const ConstVector &dc, Vector &dd,
-                   const SylvParams &ps);
+  GeneralSylvester(int ord, int n, int m, int zero_cols, const ConstVector& da,
+                   const ConstVector& db, const ConstVector& dc, Vector& dd, const SylvParams& ps);
   virtual ~GeneralSylvester() = default;
   int
   getM() const
@@ -69,23 +65,24 @@ public:
   {
     return a.nrows();
   }
-  const double *
+  const double*
   getResult() const
   {
     return d.base();
   }
-  const SylvParams &
+  const SylvParams&
   getParams() const
   {
     return pars;
   }
-  SylvParams &
+  SylvParams&
   getParams()
   {
     return pars;
   }
   void solve();
-  void check(const ConstVector &ds);
+  void check(const ConstVector& ds);
+
 private:
   void init();
 };
diff --git a/mex/sources/libkorder/sylv/IterativeSylvester.cc b/mex/sources/libkorder/sylv/IterativeSylvester.cc
index 86a3e74bcad22e9a6485d26ed407812ec9fcf4ba..49a5f7123aa0e9f6911a01c03fdf92131e38f66d 100644
--- a/mex/sources/libkorder/sylv/IterativeSylvester.cc
+++ b/mex/sources/libkorder/sylv/IterativeSylvester.cc
@@ -22,7 +22,7 @@
 #include "KronUtils.hh"
 
 void
-IterativeSylvester::solve(SylvParams &pars, KronVector &x) const
+IterativeSylvester::solve(SylvParams& pars, KronVector& x) const
 {
   int max_steps = *(pars.max_num_iter);
   int steps = 1;
@@ -45,9 +45,9 @@ IterativeSylvester::solve(SylvParams &pars, KronVector &x) const
 }
 
 double
-IterativeSylvester::performFirstStep(KronVector &x) const
+IterativeSylvester::performFirstStep(KronVector& x) const
 {
-  KronVector xtmp(const_cast<const KronVector &>(x));
+  KronVector xtmp(const_cast<const KronVector&>(x));
   KronUtils::multKron(*matrixF, *matrixK, xtmp);
   x.add(-1., xtmp);
   double norm = xtmp.getMax();
@@ -55,10 +55,9 @@ IterativeSylvester::performFirstStep(KronVector &x) const
 }
 
 double
-IterativeSylvester::performStep(const QuasiTriangular &k, const QuasiTriangular &f,
-                                KronVector &x)
+IterativeSylvester::performStep(const QuasiTriangular& k, const QuasiTriangular& f, KronVector& x)
 {
-  KronVector xtmp(const_cast<const KronVector &>(x));
+  KronVector xtmp(const_cast<const KronVector&>(x));
   KronUtils::multKron(f, k, xtmp);
   x.add(1.0, xtmp);
   double norm = xtmp.getMax();
diff --git a/mex/sources/libkorder/sylv/IterativeSylvester.hh b/mex/sources/libkorder/sylv/IterativeSylvester.hh
index 5d40146f629f29303724d2a31297b38d1041da81..85ad47a0d49ec0e4a731101198b2cc08fb5d03bc 100644
--- a/mex/sources/libkorder/sylv/IterativeSylvester.hh
+++ b/mex/sources/libkorder/sylv/IterativeSylvester.hh
@@ -21,31 +21,30 @@
 #ifndef ITERATIVE_SYLVESTER_H
 #define ITERATIVE_SYLVESTER_H
 
-#include "SylvesterSolver.hh"
 #include "KronVector.hh"
 #include "QuasiTriangular.hh"
 #include "SimilarityDecomp.hh"
+#include "SylvesterSolver.hh"
 
 class IterativeSylvester : public SylvesterSolver
 {
 public:
-  IterativeSylvester(const QuasiTriangular &k, const QuasiTriangular &f)
-    : SylvesterSolver(k, f)
+  IterativeSylvester(const QuasiTriangular& k, const QuasiTriangular& f) : SylvesterSolver(k, f)
   {
   }
-  IterativeSylvester(const SchurDecompZero &kdecomp, const SchurDecomp &fdecomp)
-    : SylvesterSolver(kdecomp, fdecomp)
+  IterativeSylvester(const SchurDecompZero& kdecomp, const SchurDecomp& fdecomp) :
+      SylvesterSolver(kdecomp, fdecomp)
   {
   }
-  IterativeSylvester(const SchurDecompZero &kdecomp, const SimilarityDecomp &fdecomp)
-    : SylvesterSolver(kdecomp, fdecomp)
+  IterativeSylvester(const SchurDecompZero& kdecomp, const SimilarityDecomp& fdecomp) :
+      SylvesterSolver(kdecomp, fdecomp)
   {
   }
-  void solve(SylvParams &pars, KronVector &x) const override;
+  void solve(SylvParams& pars, KronVector& x) const override;
+
 private:
-  double performFirstStep(KronVector &x) const;
-  static double performStep(const QuasiTriangular &k, const QuasiTriangular &f,
-                            KronVector &x);
+  double performFirstStep(KronVector& x) const;
+  static double performStep(const QuasiTriangular& k, const QuasiTriangular& f, KronVector& x);
 };
 
 #endif /* ITERATIVE_SYLVESTER_H */
diff --git a/mex/sources/libkorder/sylv/KronUtils.cc b/mex/sources/libkorder/sylv/KronUtils.cc
index d8b60dfbc2e532f28d628e8fb4081468167ba9f0..462bf8909bdfc82679076b34621ab70ffc04a637 100644
--- a/mex/sources/libkorder/sylv/KronUtils.cc
+++ b/mex/sources/libkorder/sylv/KronUtils.cc
@@ -22,8 +22,7 @@
 #include "int_power.hh"
 
 void
-KronUtils::multAtLevel(int level, const QuasiTriangular &t,
-                       KronVector &x)
+KronUtils::multAtLevel(int level, const QuasiTriangular& t, KronVector& x)
 {
   if (0 < level && level < x.getDepth())
     for (int i = 0; i < x.getM(); i++)
@@ -38,7 +37,7 @@ KronUtils::multAtLevel(int level, const QuasiTriangular &t,
     }
   else if (0 == level && 0 == x.getDepth())
     {
-      Vector b(const_cast<const KronVector &>(x));
+      Vector b(const_cast<const KronVector&>(x));
       t.multVec(x, b);
     }
   else // 0 < level == depth
@@ -46,8 +45,7 @@ KronUtils::multAtLevel(int level, const QuasiTriangular &t,
 }
 
 void
-KronUtils::multAtLevelTrans(int level, const QuasiTriangular &t,
-                            KronVector &x)
+KronUtils::multAtLevelTrans(int level, const QuasiTriangular& t, KronVector& x)
 {
   if (0 < level && level < x.getDepth())
     for (int i = 0; i < x.getM(); i++)
@@ -62,7 +60,7 @@ KronUtils::multAtLevelTrans(int level, const QuasiTriangular &t,
     }
   else if (level == 0 && 0 == x.getDepth())
     {
-      Vector b(const_cast<const KronVector &>(x));
+      Vector b(const_cast<const KronVector&>(x));
       t.multVecTrans(x, b);
     }
   else // 0 < level == depth
@@ -70,8 +68,7 @@ KronUtils::multAtLevelTrans(int level, const QuasiTriangular &t,
 }
 
 void
-KronUtils::multKron(const QuasiTriangular &f, const QuasiTriangular &k,
-                    KronVector &x)
+KronUtils::multKron(const QuasiTriangular& f, const QuasiTriangular& k, KronVector& x)
 {
   multAtLevel(0, k, x);
   if (x.getDepth() > 0)
diff --git a/mex/sources/libkorder/sylv/KronUtils.hh b/mex/sources/libkorder/sylv/KronUtils.hh
index d0ae80c547b9e6ce41d1e6c6eb273d7456e4545b..cfa1d1bc96b72f67d0eaeabfd11e412e07ca9da0 100644
--- a/mex/sources/libkorder/sylv/KronUtils.hh
+++ b/mex/sources/libkorder/sylv/KronUtils.hh
@@ -31,14 +31,11 @@ public:
      T must be m×m, number of ⊗ is d, level is the number of Iₘ’s
      between T and Iₙ plus 1. If level=0, then we multiply by Iₘ⊗…⊗Iₘ⊗T,
      T must be n×n. */
-  static void multAtLevel(int level, const QuasiTriangular &t,
-                          KronVector &x);
-  static void multAtLevelTrans(int level, const QuasiTriangular &t,
-                               KronVector &x);
+  static void multAtLevel(int level, const QuasiTriangular& t, KronVector& x);
+  static void multAtLevelTrans(int level, const QuasiTriangular& t, KronVector& x);
 
   // Computes x=(Fᵀ⊗Fᵀ⊗…⊗K)·x
-  static void multKron(const QuasiTriangular &f, const QuasiTriangular &k,
-                       KronVector &x);
+  static void multKron(const QuasiTriangular& f, const QuasiTriangular& k, KronVector& x);
 };
 
 #endif /* KRON_UTILS_H */
diff --git a/mex/sources/libkorder/sylv/KronVector.cc b/mex/sources/libkorder/sylv/KronVector.cc
index 60bc5de184ac2167f8d9cfb198ed9cdef45e7121..939bea7e674ddd1171182d9f9d68d11a2f4d3f70 100644
--- a/mex/sources/libkorder/sylv/KronVector.cc
+++ b/mex/sources/libkorder/sylv/KronVector.cc
@@ -24,33 +24,30 @@
 
 #include <utility>
 
-KronVector::KronVector(int mm, int nn, int dp)
-  : Vector(power(mm, dp)*nn), m(mm), n(nn), depth(dp)
+KronVector::KronVector(int mm, int nn, int dp) : Vector(power(mm, dp) * nn), m(mm), n(nn), depth(dp)
 {
 }
 
-KronVector::KronVector(Vector &v, int mm, int nn, int dp)
-  : Vector(v), m(mm), n(nn), depth(dp)
+KronVector::KronVector(Vector& v, int mm, int nn, int dp) : Vector(v), m(mm), n(nn), depth(dp)
 {
-  if (length() != power(m, depth)*n)
+  if (length() != power(m, depth) * n)
     throw SYLV_MES_EXCEPTION("Bad conversion KronVector from Vector.");
 }
 
-KronVector::KronVector(KronVector &v, int i)
-  : Vector(v, i*power(v.m, v.depth-1)*v.n, power(v.m, v.depth-1)*v.n), m(v.m), n(v.n),
-    depth(v.depth-1)
+KronVector::KronVector(KronVector& v, int i) :
+    Vector(v, i * power(v.m, v.depth - 1) * v.n, power(v.m, v.depth - 1) * v.n), m(v.m), n(v.n),
+    depth(v.depth - 1)
 {
   if (depth < 0)
     throw SYLV_MES_EXCEPTION("Bad KronVector pick, depth < 0.");
 }
 
-KronVector::KronVector(const ConstKronVector &v)
-  : Vector(v), m(v.m), n(v.n), depth(v.depth)
+KronVector::KronVector(const ConstKronVector& v) : Vector(v), m(v.m), n(v.n), depth(v.depth)
 {
 }
 
-KronVector &
-KronVector::operator=(const ConstKronVector &v)
+KronVector&
+KronVector::operator=(const ConstKronVector& v)
 {
   Vector::operator=(v);
   m = v.m;
@@ -59,8 +56,8 @@ KronVector::operator=(const ConstKronVector &v)
   return *this;
 }
 
-KronVector &
-KronVector::operator=(const Vector &v)
+KronVector&
+KronVector::operator=(const Vector& v)
 {
   if (length() != v.length())
     throw SYLV_MES_EXCEPTION("Wrong lengths for vector operator =.");
@@ -68,37 +65,37 @@ KronVector::operator=(const Vector &v)
   return *this;
 }
 
-ConstKronVector::ConstKronVector(const KronVector &v)
-  : ConstVector(v), m(v.m), n(v.n), depth(v.depth)
+ConstKronVector::ConstKronVector(const KronVector& v) :
+    ConstVector(v), m(v.m), n(v.n), depth(v.depth)
 {
 }
 
-ConstKronVector::ConstKronVector(const Vector &v, int mm, int nn, int dp)
-  : ConstVector(v), m(mm), n(nn), depth(dp)
+ConstKronVector::ConstKronVector(const Vector& v, int mm, int nn, int dp) :
+    ConstVector(v), m(mm), n(nn), depth(dp)
 {
-  if (length() != power(m, depth)*n)
+  if (length() != power(m, depth) * n)
     throw SYLV_MES_EXCEPTION("Bad conversion KronVector from Vector.");
 }
 
-ConstKronVector::ConstKronVector(ConstVector v, int mm, int nn, int dp)
-  : ConstVector(std::move(v)), m(mm), n(nn), depth(dp)
+ConstKronVector::ConstKronVector(ConstVector v, int mm, int nn, int dp) :
+    ConstVector(std::move(v)), m(mm), n(nn), depth(dp)
 {
-  if (length() != power(m, depth)*n)
+  if (length() != power(m, depth) * n)
     throw SYLV_MES_EXCEPTION("Bad conversion KronVector from Vector.");
 }
 
-ConstKronVector::ConstKronVector(const KronVector &v, int i)
-  : ConstVector(v, i*power(v.getM(), v.getDepth()-1)*v.getN(),
-                power(v.getM(), v.getDepth()-1)*v.getN()),
-    m(v.getM()), n(v.getN()), depth(v.getDepth()-1)
+ConstKronVector::ConstKronVector(const KronVector& v, int i) :
+    ConstVector(v, i * power(v.getM(), v.getDepth() - 1) * v.getN(),
+                power(v.getM(), v.getDepth() - 1) * v.getN()),
+    m(v.getM()), n(v.getN()), depth(v.getDepth() - 1)
 {
   if (depth < 0)
     throw SYLV_MES_EXCEPTION("Bad KronVector pick, depth < 0.");
 }
 
-ConstKronVector::ConstKronVector(const ConstKronVector &v, int i)
-  : ConstVector(v, i*power(v.m, v.depth-1)*v.n, power(v.m, v.depth-1)*v.n),
-    m(v.getM()), n(v.getN()), depth(v.getDepth()-1)
+ConstKronVector::ConstKronVector(const ConstKronVector& v, int i) :
+    ConstVector(v, i * power(v.m, v.depth - 1) * v.n, power(v.m, v.depth - 1) * v.n), m(v.getM()),
+    n(v.getN()), depth(v.getDepth() - 1)
 {
   if (depth < 0)
     throw SYLV_MES_EXCEPTION("Bad KronVector pick, depth < 0.");
diff --git a/mex/sources/libkorder/sylv/KronVector.hh b/mex/sources/libkorder/sylv/KronVector.hh
index 9c2a8d70052a9f59856efbdd3f5b91bc87c9ab4d..1f2f679bbd96728e5fc6fdfd7148b435548931ce 100644
--- a/mex/sources/libkorder/sylv/KronVector.hh
+++ b/mex/sources/libkorder/sylv/KronVector.hh
@@ -28,23 +28,25 @@ class ConstKronVector;
 class KronVector : public Vector
 {
   friend class ConstKronVector;
+
 protected:
-  int m{0};
-  int n{0};
-  int depth{0};
+  int m {0};
+  int n {0};
+  int depth {0};
+
 public:
   KronVector() = default;
-  KronVector(const KronVector &v) = default;
-  KronVector(KronVector &&v) = default;
-  KronVector(int mm, int nn, int dp); // new instance
-  KronVector(Vector &v, int mm, int nn, int dp); // conversion
-  KronVector(KronVector &, int i); // picks i-th subvector
+  KronVector(const KronVector& v) = default;
+  KronVector(KronVector&& v) = default;
+  KronVector(int mm, int nn, int dp);            // new instance
+  KronVector(Vector& v, int mm, int nn, int dp); // conversion
+  KronVector(KronVector&, int i);                // picks i-th subvector
   // We don't want implict conversion from ConstKronVector, since it's expensive
-  explicit KronVector(const ConstKronVector &v); // new instance and copy
-  KronVector &operator=(const KronVector &v) = default;
-  KronVector &operator=(KronVector &&v) = default;
-  KronVector &operator=(const ConstKronVector &v);
-  KronVector &operator=(const Vector &v);
+  explicit KronVector(const ConstKronVector& v); // new instance and copy
+  KronVector& operator=(const KronVector& v) = default;
+  KronVector& operator=(KronVector&& v) = default;
+  KronVector& operator=(const ConstKronVector& v);
+  KronVector& operator=(const Vector& v);
   int
   getM() const
   {
@@ -65,21 +67,23 @@ public:
 class ConstKronVector : public ConstVector
 {
   friend class KronVector;
+
 protected:
   int m;
   int n;
   int depth;
+
 public:
   // Implicit conversion from KronVector is ok, since it's cheap
-  ConstKronVector(const KronVector &v);
-  ConstKronVector(const ConstKronVector &v) = default;
-  ConstKronVector(ConstKronVector &&v) = default;
-  ConstKronVector(const Vector &v, int mm, int nn, int dp);
+  ConstKronVector(const KronVector& v);
+  ConstKronVector(const ConstKronVector& v) = default;
+  ConstKronVector(ConstKronVector&& v) = default;
+  ConstKronVector(const Vector& v, int mm, int nn, int dp);
   ConstKronVector(ConstVector v, int mm, int nn, int dp);
-  ConstKronVector(const KronVector &v, int i);
-  ConstKronVector(const ConstKronVector &v, int i);
-  ConstKronVector &operator=(const ConstKronVector &v) = delete;
-  ConstKronVector &operator=(ConstKronVector &&v) = delete;
+  ConstKronVector(const KronVector& v, int i);
+  ConstKronVector(const ConstKronVector& v, int i);
+  ConstKronVector& operator=(const ConstKronVector& v) = delete;
+  ConstKronVector& operator=(ConstKronVector&& v) = delete;
   int
   getM() const
   {
diff --git a/mex/sources/libkorder/sylv/QuasiTriangular.cc b/mex/sources/libkorder/sylv/QuasiTriangular.cc
index 7923bb1a30c593529e07a5fc8c8bc81d849511cb..cc68318c791f87ab8124f716b58cf2456c489f49 100644
--- a/mex/sources/libkorder/sylv/QuasiTriangular.cc
+++ b/mex/sources/libkorder/sylv/QuasiTriangular.cc
@@ -19,27 +19,27 @@
  */
 
 #include "QuasiTriangular.hh"
-#include "SylvException.hh"
 #include "SchurDecomp.hh"
+#include "SylvException.hh"
 #include "int_power.hh"
 
 #include <dynblas.h>
 
 #include <cmath>
 #include <iostream>
-#include <sstream>
 #include <limits>
+#include <sstream>
 
 double
 DiagonalBlock::getDeterminant() const
 {
-  return (*alpha)*(*alpha) + getSBeta();
+  return (*alpha) * (*alpha) + getSBeta();
 }
 
 double
 DiagonalBlock::getSBeta() const
 {
-  return -(*beta1)*(*beta2);
+  return -(*beta1) * (*beta2);
 }
 
 double
@@ -63,12 +63,12 @@ DiagonalBlock::setReal()
 }
 
 void
-DiagonalBlock::checkBlock(const double *d, int d_size)
+DiagonalBlock::checkBlock(const double* d, int d_size)
 {
-  const double *a1 = d + jbar*d_size+jbar;
-  const double *b1 = a1 + d_size;
-  const double *b2 = a1 + 1;
-  const double *a2 = b1 + 1;
+  const double* a1 = d + jbar * d_size + jbar;
+  const double* b1 = a1 + d_size;
+  const double* b2 = a1 + 1;
+  const double* a2 = b1 + 1;
   if (a1 != alpha.a1)
     throw SYLV_MES_EXCEPTION("Bad alpha1.");
   if (!real && b1 != beta1)
@@ -79,25 +79,24 @@ DiagonalBlock::checkBlock(const double *d, int d_size)
     throw SYLV_MES_EXCEPTION("Bad alpha2.");
 }
 
-Diagonal::Diagonal(double *data, int d_size)
+Diagonal::Diagonal(double* data, int d_size)
 {
   int nc = getNumComplex(data, d_size); // return nc ≤ d_size/2
   num_all = d_size - nc;
-  num_real = d_size - 2*nc;
+  num_real = d_size - 2 * nc;
 
   int jbar = 0;
   int j = 0;
   while (j < num_all)
     {
-      int id = jbar*d_size + jbar; // index of diagonal block in data
-      int ill = id + 1; // index of element below the diagonal
-      int iur = id + d_size; // index of element right to diagonal
-      int idd = id + d_size + 1; // index of element next on diagonal
-      if ((jbar < d_size-1) && !isZero(data[ill]))
+      int id = jbar * d_size + jbar; // index of diagonal block in data
+      int ill = id + 1;              // index of element below the diagonal
+      int iur = id + d_size;         // index of element right to diagonal
+      int idd = id + d_size + 1;     // index of element next on diagonal
+      if ((jbar < d_size - 1) && !isZero(data[ill]))
         {
           // it is not last column and we have nonzero below diagonal
-          blocks.emplace_back(jbar, false, &data[id], &data[idd],
-                              &data[iur], &data[ill]);
+          blocks.emplace_back(jbar, false, &data[id], &data[idd], &data[iur], &data[ill]);
           jbar++;
         }
       else
@@ -108,90 +107,87 @@ Diagonal::Diagonal(double *data, int d_size)
     }
 }
 
-Diagonal::Diagonal(double *data, const Diagonal &d)
+Diagonal::Diagonal(double* data, const Diagonal& d)
 {
   num_all = d.num_all;
   num_real = d.num_real;
   int d_size = d.getSize();
-  for (const auto &block : d)
+  for (const auto& block : d)
     {
-      double *beta1 = nullptr;
-      double *beta2 = nullptr;
-      int id = block.getIndex()*(d_size+1);
+      double* beta1 = nullptr;
+      double* beta2 = nullptr;
+      int id = block.getIndex() * (d_size + 1);
       int idd = id;
       if (!block.isReal())
         {
-          beta1 = &data[id+d_size];
-          beta2 = &data[id+1];
+          beta1 = &data[id + d_size];
+          beta2 = &data[id + 1];
           idd = id + d_size + 1;
         }
-      blocks.emplace_back(block.getIndex(), block.isReal(),
-                          &data[id], &data[idd], beta1, beta2);
+      blocks.emplace_back(block.getIndex(), block.isReal(), &data[id], &data[idd], beta1, beta2);
     }
 }
 
 int
-Diagonal::getNumComplex(const double *data, int d_size)
+Diagonal::getNumComplex(const double* data, int d_size)
 {
   int num_complex = 0;
   int in = 1;
-  for (int i = 0; i < d_size-1; i++, in = in + d_size + 1)
+  for (int i = 0; i < d_size - 1; i++, in = in + d_size + 1)
     if (!isZero(data[in]))
       {
         num_complex++;
-        if (in < d_size - 2 && !isZero(data[in + d_size +1]))
+        if (in < d_size - 2 && !isZero(data[in + d_size + 1]))
           throw SYLV_MES_EXCEPTION("Matrix is not quasi-triangular");
       }
   return num_complex;
 }
 
 void
-Diagonal::changeBase(double *p)
+Diagonal::changeBase(double* p)
 {
   int d_size = getSize();
-  for (auto &it : *this)
+  for (auto& it : *this)
     {
-      const DiagonalBlock &b = it;
+      const DiagonalBlock& b = it;
       int jbar = b.getIndex();
-      int base = d_size*jbar + jbar;
+      int base = d_size * jbar + jbar;
       if (b.isReal())
         {
-          DiagonalBlock bnew(jbar, true, &p[base], &p[base],
-                             nullptr, nullptr);
+          DiagonalBlock bnew(jbar, true, &p[base], &p[base], nullptr, nullptr);
           it = bnew;
         }
       else
         {
-          DiagonalBlock bnew(jbar, false, &p[base], &p[base+d_size+1],
-                             &p[base+d_size], &p[base+1]);
+          DiagonalBlock bnew(jbar, false, &p[base], &p[base + d_size + 1], &p[base + d_size],
+                             &p[base + 1]);
           it = bnew;
         }
     }
 }
 
 void
-Diagonal::getEigenValues(Vector &eig) const
+Diagonal::getEigenValues(Vector& eig) const
 {
-  if (int d_size {getSize()};
-      eig.length() != 2*d_size)
+  if (int d_size {getSize()}; eig.length() != 2 * d_size)
     {
       std::ostringstream mes;
       mes << "Wrong length of vector for eigenvalues len=" << eig.length()
-          << ", should be=" << 2*d_size << '.' << std::endl;
+          << ", should be=" << 2 * d_size << '.' << std::endl;
       throw SYLV_MES_EXCEPTION(mes.str());
     }
-  for (const auto &b : *this)
+  for (const auto& b : *this)
     {
       int ind = b.getIndex();
-      eig[2*ind] = *(b.getAlpha());
+      eig[2 * ind] = *(b.getAlpha());
       if (b.isReal())
-        eig[2*ind+1] = 0.0;
+        eig[2 * ind + 1] = 0.0;
       else
         {
           double beta = std::sqrt(b.getSBeta());
-          eig[2*ind+1] = beta;
-          eig[2*ind+2] = eig[2*ind];
-          eig[2*ind+3] = -beta;
+          eig[2 * ind + 1] = beta;
+          eig[2 * ind + 2] = eig[2 * ind];
+          eig[2 * ind + 3] = -beta;
         }
     }
 }
@@ -208,25 +204,25 @@ Diagonal::swapLogically(diag_iter it)
   if (it->isReal() && !itp->isReal())
     {
       // first is real, second is complex
-      double *d1 = it->alpha.a1;
-      double *d2 = itp->alpha.a1;
-      double *d3 = itp->alpha.a2;
+      double* d1 = it->alpha.a1;
+      double* d2 = itp->alpha.a1;
+      double* d3 = itp->alpha.a2;
       // swap
       DiagonalBlock new_it(it->jbar, d1, d2);
       *it = new_it;
-      DiagonalBlock new_itp(itp->jbar+1, d3);
+      DiagonalBlock new_itp(itp->jbar + 1, d3);
       *itp = new_itp;
     }
   else if (!it->isReal() && itp->isReal())
     {
       // first is complex, second is real
-      double *d1 = it->alpha.a1;
-      double *d2 = it->alpha.a2;
-      double *d3 = itp->alpha.a1;
+      double* d1 = it->alpha.a1;
+      double* d2 = it->alpha.a2;
+      double* d3 = itp->alpha.a1;
       // swap
       DiagonalBlock new_it(it->jbar, d1);
       *it = new_it;
-      DiagonalBlock new_itp(itp->jbar-1, d2, d3);
+      DiagonalBlock new_itp(itp->jbar - 1, d2, d3);
       *itp = new_itp;
     }
 }
@@ -238,12 +234,12 @@ Diagonal::checkConsistency(diag_iter it)
     {
       it->getBeta2() = 0.0; // put exact zero
       int jbar = it->getIndex();
-      double *d2 = it->alpha.a2;
+      double* d2 = it->alpha.a2;
       it->alpha.a2 = it->alpha.a1;
       it->real = true;
       it->beta1 = nullptr;
       it->beta2 = nullptr;
-      blocks.emplace(++it, jbar+1, d2);
+      blocks.emplace(++it, jbar + 1, d2);
       num_real += 2;
       num_all++;
     }
@@ -260,7 +256,7 @@ Diagonal::getAverageSize(diag_iter start, diag_iter end)
       res += run->getSize();
     }
   if (num > 0)
-    res = res/num;
+    res = res / num;
   return res;
 }
 
@@ -270,8 +266,7 @@ Diagonal::findClosestBlock(diag_iter start, diag_iter end, double a)
   diag_iter closest = start;
   double minim {std::numeric_limits<double>::infinity()};
   for (diag_iter run = start; run != end; ++run)
-    if (double dist = std::abs(a - run->getSize());
-        dist < minim)
+    if (double dist = std::abs(a - run->getSize()); dist < minim)
       {
         minim = dist;
         closest = run;
@@ -285,8 +280,7 @@ Diagonal::findNextLargerBlock(diag_iter start, diag_iter end, double a)
   diag_iter closest = start;
   double minim {std::numeric_limits<double>::infinity()};
   for (diag_iter run = start; run != end; ++run)
-    if (double dist = run->getSize() - a;
-        0 <= dist && dist < minim)
+    if (double dist = run->getSize() - a; 0 <= dist && dist < minim)
       {
         minim = dist;
         closest = run;
@@ -300,14 +294,12 @@ Diagonal::print() const
   auto ff = std::cout.flags();
   std::cout << "Num real: " << getNumReal() << ", num complex: " << getNumComplex() << std::endl
             << std::fixed;
-  for (const auto &it : *this)
+  for (const auto& it : *this)
     if (it.isReal())
       std::cout << "real: jbar=" << it.getIndex() << ", alpha=" << *(it.getAlpha()) << std::endl;
     else
-      std::cout << "complex: jbar=" << it.getIndex()
-                << ", alpha=" << *(it.getAlpha())
-                << ", beta1=" << it.getBeta1()
-                << ", beta2=" << it.getBeta2() << std::endl;
+      std::cout << "complex: jbar=" << it.getIndex() << ", alpha=" << *(it.getAlpha())
+                << ", beta1=" << it.getBeta1() << ", beta2=" << it.getBeta2() << std::endl;
   std::cout.flags(ff);
 }
 
@@ -318,28 +310,28 @@ Diagonal::isZero(double p)
 }
 
 QuasiTriangular::const_col_iter
-QuasiTriangular::col_begin(const DiagonalBlock &b) const
+QuasiTriangular::col_begin(const DiagonalBlock& b) const
 {
   int jbar = b.getIndex();
   int d_size = diagonal.getSize();
-  return const_col_iter(&getData()[jbar*d_size], d_size, b.isReal(), 0);
+  return const_col_iter(&getData()[jbar * d_size], d_size, b.isReal(), 0);
 }
 
 QuasiTriangular::col_iter
-QuasiTriangular::col_begin(const DiagonalBlock &b)
+QuasiTriangular::col_begin(const DiagonalBlock& b)
 {
   int jbar = b.getIndex();
   int d_size = diagonal.getSize();
-  return col_iter(&getData()[jbar*d_size], d_size, b.isReal(), 0);
+  return col_iter(&getData()[jbar * d_size], d_size, b.isReal(), 0);
 }
 
 QuasiTriangular::const_row_iter
-QuasiTriangular::row_begin(const DiagonalBlock &b) const
+QuasiTriangular::row_begin(const DiagonalBlock& b) const
 {
   int jbar = b.getIndex();
   int d_size = diagonal.getSize();
-  int off = jbar*d_size+jbar+d_size;
-  int col = jbar+1;
+  int off = jbar * d_size + jbar + d_size;
+  int col = jbar + 1;
   if (!b.isReal())
     {
       off = off + d_size;
@@ -349,12 +341,12 @@ QuasiTriangular::row_begin(const DiagonalBlock &b) const
 }
 
 QuasiTriangular::row_iter
-QuasiTriangular::row_begin(const DiagonalBlock &b)
+QuasiTriangular::row_begin(const DiagonalBlock& b)
 {
   int jbar = b.getIndex();
   int d_size = diagonal.getSize();
-  int off = jbar*d_size+jbar+d_size;
-  int col = jbar+1;
+  int off = jbar * d_size + jbar + d_size;
+  int col = jbar + 1;
   if (!b.isReal())
     {
       off = off + d_size;
@@ -364,113 +356,112 @@ QuasiTriangular::row_begin(const DiagonalBlock &b)
 }
 
 QuasiTriangular::const_col_iter
-QuasiTriangular::col_end(const DiagonalBlock &b) const
+QuasiTriangular::col_end(const DiagonalBlock& b) const
 {
   int jbar = b.getIndex();
   int d_size = diagonal.getSize();
-  return const_col_iter(getData().base()+jbar*d_size+jbar, d_size, b.isReal(),
-                        jbar);
+  return const_col_iter(getData().base() + jbar * d_size + jbar, d_size, b.isReal(), jbar);
 }
 
 QuasiTriangular::col_iter
-QuasiTriangular::col_end(const DiagonalBlock &b)
+QuasiTriangular::col_end(const DiagonalBlock& b)
 {
   int jbar = b.getIndex();
   int d_size = diagonal.getSize();
-  return col_iter(&getData()[jbar*d_size+jbar], d_size, b.isReal(), jbar);
+  return col_iter(&getData()[jbar * d_size + jbar], d_size, b.isReal(), jbar);
 }
 
 QuasiTriangular::const_row_iter
-QuasiTriangular::row_end(const DiagonalBlock &b) const
+QuasiTriangular::row_end(const DiagonalBlock& b) const
 {
   int jbar = b.getIndex();
   int d_size = diagonal.getSize();
-  return const_row_iter(&getData()[d_size*d_size+jbar], d_size, b.isReal(),
-                        d_size);
+  return const_row_iter(&getData()[d_size * d_size + jbar], d_size, b.isReal(), d_size);
 }
 
 QuasiTriangular::row_iter
-QuasiTriangular::row_end(const DiagonalBlock &b)
+QuasiTriangular::row_end(const DiagonalBlock& b)
 {
   int jbar = b.getIndex();
   int d_size = diagonal.getSize();
-  return row_iter(&getData()[d_size*d_size+jbar], d_size, b.isReal(), d_size);
+  return row_iter(&getData()[d_size * d_size + jbar], d_size, b.isReal(), d_size);
 }
 
-QuasiTriangular::QuasiTriangular(double r, const QuasiTriangular &t)
-  : SqSylvMatrix(t.nrows()), diagonal(getData().base(), t.diagonal)
+QuasiTriangular::QuasiTriangular(double r, const QuasiTriangular& t) :
+    SqSylvMatrix(t.nrows()), diagonal(getData().base(), t.diagonal)
 {
   setMatrix(r, t);
 }
 
-QuasiTriangular::QuasiTriangular(double r, const QuasiTriangular &t,
-                                 double r2, const QuasiTriangular &t2)
-  : SqSylvMatrix(t.nrows()), diagonal(getData().base(), t.diagonal)
+QuasiTriangular::QuasiTriangular(double r, const QuasiTriangular& t, double r2,
+                                 const QuasiTriangular& t2) :
+    SqSylvMatrix(t.nrows()),
+    diagonal(getData().base(), t.diagonal)
 {
   setMatrix(r, t);
   addMatrix(r2, t2);
 }
 
-QuasiTriangular::QuasiTriangular(const QuasiTriangular &t)
-  : SqSylvMatrix(t), diagonal(getData().base(), t.diagonal)
+QuasiTriangular::QuasiTriangular(const QuasiTriangular& t) :
+    SqSylvMatrix(t), diagonal(getData().base(), t.diagonal)
 {
 }
 
-QuasiTriangular::QuasiTriangular(const ConstVector &d, int d_size)
-  : SqSylvMatrix(Vector{d}, d_size), diagonal(getData().base(), d_size)
+QuasiTriangular::QuasiTriangular(const ConstVector& d, int d_size) :
+    SqSylvMatrix(Vector {d}, d_size), diagonal(getData().base(), d_size)
 {
 }
 
-QuasiTriangular::QuasiTriangular([[maybe_unused]] const std::string &dummy, const QuasiTriangular &t)
-  : SqSylvMatrix(t.nrows()), diagonal(getData().base(), t.diagonal)
+QuasiTriangular::QuasiTriangular([[maybe_unused]] const std::string& dummy,
+                                 const QuasiTriangular& t) :
+    SqSylvMatrix(t.nrows()),
+    diagonal(getData().base(), t.diagonal)
 {
   Vector aux(t.getData());
   blas_int d_size = diagonal.getSize();
   double alpha = 1.0;
   double beta = 0.0;
   blas_int lda = t.getLD(), ldb = t.getLD(), ldc = ld;
-  dgemm("N", "N", &d_size, &d_size, &d_size, &alpha, aux.base(),
-        &lda, t.getData().base(), &ldb, &beta, getData().base(), &ldc);
+  dgemm("N", "N", &d_size, &d_size, &d_size, &alpha, aux.base(), &lda, t.getData().base(), &ldb,
+        &beta, getData().base(), &ldc);
 }
 
-QuasiTriangular::QuasiTriangular(const SchurDecomp &decomp)
-  : SqSylvMatrix(decomp.getT()),
-    diagonal(getData().base(), decomp.getDim())
+QuasiTriangular::QuasiTriangular(const SchurDecomp& decomp) :
+    SqSylvMatrix(decomp.getT()), diagonal(getData().base(), decomp.getDim())
 {
 }
 
 // This pads matrix with intial columns with zeros
-QuasiTriangular::QuasiTriangular(const SchurDecompZero &decomp)
-  : SqSylvMatrix(decomp.getDim())
+QuasiTriangular::QuasiTriangular(const SchurDecompZero& decomp) : SqSylvMatrix(decomp.getDim())
 {
   // nullify first decomp.getZeroCols() columns
-  int zeros = decomp.getZeroCols()*decomp.getDim();
+  int zeros = decomp.getZeroCols() * decomp.getDim();
   Vector zv(getData(), 0, zeros);
   zv.zeros();
   // fill right upper part with decomp.getRU()
   for (int i = 0; i < decomp.getRU().nrows(); i++)
     for (int j = 0; j < decomp.getRU().ncols(); j++)
-      getData()[(j+decomp.getZeroCols())*decomp.getDim()+i] = decomp.getRU().get(i, j);
+      getData()[(j + decomp.getZeroCols()) * decomp.getDim() + i] = decomp.getRU().get(i, j);
 
   // fill right lower part with decomp.getT()
   for (int i = 0; i < decomp.getT().nrows(); i++)
     for (int j = 0; j < decomp.getT().ncols(); j++)
-      getData()[(j+decomp.getZeroCols())*decomp.getDim()+decomp.getZeroCols()+i]
-        = decomp.getT().get(i, j);
+      getData()[(j + decomp.getZeroCols()) * decomp.getDim() + decomp.getZeroCols() + i]
+          = decomp.getT().get(i, j);
 
   // construct diagonal
-  diagonal = Diagonal{getData().base(), decomp.getDim()};
+  diagonal = Diagonal {getData().base(), decomp.getDim()};
 }
 
 void
-QuasiTriangular::setMatrix(double r, const QuasiTriangular &t)
+QuasiTriangular::setMatrix(double r, const QuasiTriangular& t)
 {
   getData().zeros();
   getData().add(r, t.getData());
 }
 
 void
-QuasiTriangular::addMatrix(double r, const QuasiTriangular &t)
+QuasiTriangular::addMatrix(double r, const QuasiTriangular& t)
 {
   getData().add(r, t.getData());
 }
@@ -483,21 +474,21 @@ QuasiTriangular::addUnit()
 }
 
 void
-QuasiTriangular::solve(Vector &x, const ConstVector &b, double &eig_min)
+QuasiTriangular::solve(Vector& x, const ConstVector& b, double& eig_min)
 {
   x = b;
   solvePre(x, eig_min);
 }
 
 void
-QuasiTriangular::solveTrans(Vector &x, const ConstVector &b, double &eig_min)
+QuasiTriangular::solveTrans(Vector& x, const ConstVector& b, double& eig_min)
 {
   x = b;
   solvePreTrans(x, eig_min);
 }
 
 void
-QuasiTriangular::solvePre(Vector &x, double &eig_min)
+QuasiTriangular::solvePre(Vector& x, double& eig_min)
 {
   addUnit();
   for (diag_iter di = diag_begin(); di != diag_end(); ++di)
@@ -506,10 +497,10 @@ QuasiTriangular::solvePre(Vector &x, double &eig_min)
       if (!di->isReal())
         {
           eig_size = di->getDeterminant();
-          eliminateLeft(di->getIndex()+1, di->getIndex(), x);
+          eliminateLeft(di->getIndex() + 1, di->getIndex(), x);
         }
       else
-        eig_size = *di->getAlpha()*(*di->getAlpha());
+        eig_size = *di->getAlpha() * (*di->getAlpha());
       eig_min = std::min(eig_min, eig_size);
     }
 
@@ -520,7 +511,7 @@ QuasiTriangular::solvePre(Vector &x, double &eig_min)
 }
 
 void
-QuasiTriangular::solvePreTrans(Vector &x, double &eig_min)
+QuasiTriangular::solvePreTrans(Vector& x, double& eig_min)
 {
   addUnit();
   for (diag_iter di = diag_begin(); di != diag_end(); ++di)
@@ -529,10 +520,10 @@ QuasiTriangular::solvePreTrans(Vector &x, double &eig_min)
       if (!di->isReal())
         {
           eig_size = di->getDeterminant();
-          eliminateRight(di->getIndex()+1, di->getIndex(), x);
+          eliminateRight(di->getIndex() + 1, di->getIndex(), x);
         }
       else
-        eig_size = *di->getAlpha()*(*di->getAlpha());
+        eig_size = *di->getAlpha() * (*di->getAlpha());
       if (eig_size < eig_min)
         eig_min = eig_size;
     }
@@ -545,7 +536,7 @@ QuasiTriangular::solvePreTrans(Vector &x, double &eig_min)
 
 // Calculates x = T·b
 void
-QuasiTriangular::multVec(Vector &x, const ConstVector &b) const
+QuasiTriangular::multVec(Vector& x, const ConstVector& b) const
 {
   x = b;
   blas_int nn = diagonal.getSize();
@@ -556,12 +547,12 @@ QuasiTriangular::multVec(Vector &x, const ConstVector &b) const
     if (!di->isReal())
       {
         int jbar = di->getIndex();
-        x[jbar+1] += di->getBeta2()*(b[jbar]);
+        x[jbar + 1] += di->getBeta2() * (b[jbar]);
       }
 }
 
 void
-QuasiTriangular::multVecTrans(Vector &x, const ConstVector &b) const
+QuasiTriangular::multVecTrans(Vector& x, const ConstVector& b) const
 {
   x = b;
   blas_int nn = diagonal.getSize();
@@ -572,31 +563,31 @@ QuasiTriangular::multVecTrans(Vector &x, const ConstVector &b) const
     if (!di->isReal())
       {
         int jbar = di->getIndex();
-        x[jbar] += di->getBeta2()*b[jbar+1];
+        x[jbar] += di->getBeta2() * b[jbar + 1];
       }
 }
 
 void
-QuasiTriangular::multaVec(Vector &x, const ConstVector &b) const
+QuasiTriangular::multaVec(Vector& x, const ConstVector& b) const
 {
-  Vector tmp(const_cast<const Vector &>(x)); // new copy
+  Vector tmp(const_cast<const Vector&>(x)); // new copy
   multVec(x, b);
   x.add(1.0, tmp);
 }
 
 void
-QuasiTriangular::multaVecTrans(Vector &x, const ConstVector &b) const
+QuasiTriangular::multaVecTrans(Vector& x, const ConstVector& b) const
 {
-  Vector tmp(const_cast<const Vector &>(x)); // new copy
+  Vector tmp(const_cast<const Vector&>(x)); // new copy
   multVecTrans(x, b);
   x.add(1.0, tmp);
 }
 
 // Calculates x=x+(this⊗I)·b, where size of I is given by b (KronVector)
 void
-QuasiTriangular::multaKron(KronVector &x, const ConstKronVector &b) const
+QuasiTriangular::multaKron(KronVector& x, const ConstKronVector& b) const
 {
-  int id = b.getN()*power(b.getM(), b.getDepth()-1);
+  int id = b.getN() * power(b.getM(), b.getDepth() - 1);
   ConstGeneralMatrix b_resh(b, id, b.getM());
   GeneralMatrix x_resh(x, id, b.getM());
   x_resh.multAndAdd(b_resh, ConstGeneralMatrix(*this), "trans");
@@ -604,38 +595,38 @@ QuasiTriangular::multaKron(KronVector &x, const ConstKronVector &b) const
 
 // Calculates x=x+(this⊗I)·b, where size of I is given by b (KronVector)
 void
-QuasiTriangular::multaKronTrans(KronVector &x, const ConstKronVector &b) const
+QuasiTriangular::multaKronTrans(KronVector& x, const ConstKronVector& b) const
 {
-  int id = b.getN()*power(b.getM(), b.getDepth()-1);
+  int id = b.getN() * power(b.getM(), b.getDepth() - 1);
   ConstGeneralMatrix b_resh(b, id, b.getM());
   GeneralMatrix x_resh(x, id, b.getM());
   x_resh.multAndAdd(b_resh, ConstGeneralMatrix(*this));
 }
 
 void
-QuasiTriangular::multKron(KronVector &x) const
+QuasiTriangular::multKron(KronVector& x) const
 {
-  KronVector b(const_cast<const KronVector &>(x)); // make copy
+  KronVector b(const_cast<const KronVector&>(x)); // make copy
   x.zeros();
   multaKron(x, b);
 }
 
 void
-QuasiTriangular::multKronTrans(KronVector &x) const
+QuasiTriangular::multKronTrans(KronVector& x) const
 {
-  KronVector b(const_cast<const KronVector &>(x)); // make copy
+  KronVector b(const_cast<const KronVector&>(x)); // make copy
   x.zeros();
   multaKronTrans(x, b);
 }
 
 void
-QuasiTriangular::multLeftOther(GeneralMatrix &a) const
+QuasiTriangular::multLeftOther(GeneralMatrix& a) const
 {
   a.multLeft(*this);
 }
 
 void
-QuasiTriangular::multLeftOtherTrans(GeneralMatrix &a) const
+QuasiTriangular::multLeftOtherTrans(GeneralMatrix& a) const
 {
   a.multLeftTrans(*this);
 }
@@ -673,5 +664,5 @@ QuasiTriangular::findNextLargerBlock(diag_iter start, diag_iter end, double a)
 int
 QuasiTriangular::getNumOffdiagonal() const
 {
-  return diagonal.getSize()*(diagonal.getSize()-1)/2 - diagonal.getNumComplex();
+  return diagonal.getSize() * (diagonal.getSize() - 1) / 2 - diagonal.getNumComplex();
 }
diff --git a/mex/sources/libkorder/sylv/QuasiTriangular.hh b/mex/sources/libkorder/sylv/QuasiTriangular.hh
index b5a32737499fbc4a36c8e842c658bdd63c867d50..2cc5e0013f3f535cccbbd29a148c350792caadf1 100644
--- a/mex/sources/libkorder/sylv/QuasiTriangular.hh
+++ b/mex/sources/libkorder/sylv/QuasiTriangular.hh
@@ -21,9 +21,9 @@
 #ifndef QUASI_TRIANGULAR_H
 #define QUASI_TRIANGULAR_H
 
-#include "Vector.hh"
 #include "KronVector.hh"
 #include "SylvMatrix.hh"
+#include "Vector.hh"
 
 #include <list>
 #include <memory>
@@ -33,23 +33,24 @@ class Diagonal;
 class DiagPair
 {
 private:
-  double *a1;
-  double *a2;
+  double* a1;
+  double* a2;
+
 public:
   DiagPair() = default;
-  DiagPair(double *aa1, double *aa2) : a1{aa1}, a2{aa2}
+  DiagPair(double* aa1, double* aa2) : a1 {aa1}, a2 {aa2}
   {
   }
-  DiagPair(const DiagPair &p) = default;
-  DiagPair &operator=(const DiagPair &p) = default;
-  DiagPair &
+  DiagPair(const DiagPair& p) = default;
+  DiagPair& operator=(const DiagPair& p) = default;
+  DiagPair&
   operator=(double v)
   {
     *a1 = v;
     *a2 = v;
     return *this;
   }
-  const double &
+  const double&
   operator*() const
   {
     return *a1;
@@ -71,29 +72,28 @@ private:
   int jbar; // Index of block in the diagonal
   bool real;
   DiagPair alpha;
-  double *beta1;
-  double *beta2;
+  double* beta1;
+  double* beta2;
 
 public:
   DiagonalBlock() = default;
-  DiagonalBlock(int jb, bool r, double *a1, double *a2,
-                double *b1, double *b2)
-    : jbar{jb}, real{r}, alpha{a1, a2}, beta1{b1}, beta2{b2}
+  DiagonalBlock(int jb, bool r, double* a1, double* a2, double* b1, double* b2) :
+      jbar {jb}, real {r}, alpha {a1, a2}, beta1 {b1}, beta2 {b2}
   {
   }
   // Construct a complex 2×2 block
   /* β₁ and β₂ will be deduced from pointers to α₁ and α₂ */
-  DiagonalBlock(int jb, double *a1, double *a2)
-    : jbar{jb}, real{false}, alpha{a1, a2}, beta1{a2-1}, beta2{a1+1}
+  DiagonalBlock(int jb, double* a1, double* a2) :
+      jbar {jb}, real {false}, alpha {a1, a2}, beta1 {a2 - 1}, beta2 {a1 + 1}
   {
   }
   // Construct a real 1×1 block
-  DiagonalBlock(int jb, double *a1)
-    : jbar{jb}, real{true}, alpha{a1, a1}, beta1{nullptr}, beta2{nullptr}
+  DiagonalBlock(int jb, double* a1) :
+      jbar {jb}, real {true}, alpha {a1, a1}, beta1 {nullptr}, beta2 {nullptr}
   {
   }
-  DiagonalBlock(const DiagonalBlock &b) = default;
-  DiagonalBlock &operator=(const DiagonalBlock &b) = default;
+  DiagonalBlock(const DiagonalBlock& b) = default;
+  DiagonalBlock& operator=(const DiagonalBlock& b) = default;
   int
   getIndex() const
   {
@@ -104,22 +104,22 @@ public:
   {
     return real;
   }
-  const DiagPair &
+  const DiagPair&
   getAlpha() const
   {
     return alpha;
   }
-  DiagPair &
+  DiagPair&
   getAlpha()
   {
     return alpha;
   }
-  double &
+  double&
   getBeta1() const
   {
     return *beta1;
   }
-  double &
+  double&
   getBeta2() const
   {
     return *beta2;
@@ -133,7 +133,7 @@ public:
   // Transforms this block into a real one
   void setReal();
   // Verifies that the block information is consistent with the matrix d (for debugging)
-  void checkBlock(const double *d, int d_size);
+  void checkBlock(const double* d, int d_size);
   friend class Diagonal;
 };
 
@@ -143,19 +143,20 @@ class Diagonal
 public:
   using const_diag_iter = std::list<DiagonalBlock>::const_iterator;
   using diag_iter = std::list<DiagonalBlock>::iterator;
+
 private:
-  int num_all{0}; // Total number of blocks
+  int num_all {0}; // Total number of blocks
   std::list<DiagonalBlock> blocks;
-  int num_real{0}; // Number of 1×1 (real) blocks
+  int num_real {0}; // Number of 1×1 (real) blocks
 public:
   Diagonal() = default;
   // Construct the diagonal blocks of (quasi-triangular) matrix ‘data’
-  Diagonal(double *data, int d_size);
+  Diagonal(double* data, int d_size);
   /* Construct the diagonal blocks of (quasi-triangular) matrix ‘data’,
      assuming it has the same shape as ‘d’ */
-  Diagonal(double *data, const Diagonal &d);
-  Diagonal(const Diagonal &d) = default;
-  Diagonal &operator=(const Diagonal &d) = default;
+  Diagonal(double* data, const Diagonal& d);
+  Diagonal(const Diagonal& d) = default;
+  Diagonal& operator=(const Diagonal& d) = default;
   virtual ~Diagonal() = default;
 
   // Returns number of 2×2 blocks on the diagonal
@@ -174,7 +175,7 @@ public:
   int
   getSize() const
   {
-    return getNumReal() + 2*getNumComplex();
+    return getNumReal() + 2 * getNumComplex();
   }
   // Returns total number of blocks on the diagonal
   int
@@ -182,7 +183,7 @@ public:
   {
     return num_all;
   }
-  void getEigenValues(Vector &eig) const;
+  void getEigenValues(Vector& eig) const;
   void swapLogically(diag_iter it);
   void checkConsistency(diag_iter it);
   double getAverageSize(diag_iter start, diag_iter end);
@@ -212,12 +213,13 @@ public:
   }
 
   /* redefine pointers as data start at p */
-  void changeBase(double *p);
+  void changeBase(double* p);
+
 private:
   constexpr static double EPS = 1.0e-300;
   /* Computes number of 2×2 diagonal blocks on the quasi-triangular matrix
      represented by data (of size d_size×d_size) */
-  static int getNumComplex(const double *data, int d_size);
+  static int getNumComplex(const double* data, int d_size);
   // Checks whether |p|<EPS
   static bool isZero(double p);
 };
@@ -229,6 +231,7 @@ struct _matrix_iter
   int d_size;
   bool real;
   _TPtr ptr;
+
 public:
   _matrix_iter(_TPtr base, int ds, bool r)
   {
@@ -238,12 +241,12 @@ public:
   }
   virtual ~_matrix_iter() = default;
   bool
-  operator==(const _Self &it) const
+  operator==(const _Self& it) const
   {
     return ptr == it.ptr;
   }
   bool
-  operator!=(const _Self &it) const
+  operator!=(const _Self& it) const
   {
     return ptr != it.ptr;
   }
@@ -257,7 +260,7 @@ public:
   {
     return *ptr;
   }
-  virtual _Self &operator++() = 0;
+  virtual _Self& operator++() = 0;
 };
 
 template<class _TRef, class _TPtr>
@@ -266,12 +269,11 @@ class _column_iter : public _matrix_iter<_TRef, _TPtr>
   using _Tparent = _matrix_iter<_TRef, _TPtr>;
   using _Self = _column_iter<_TRef, _TPtr>;
   int row;
+
 public:
-  _column_iter(_TPtr base, int ds, bool r, int rw)
-    : _matrix_iter<_TRef, _TPtr>(base, ds, r), row(rw)
-  {
-  };
-  _Self &
+  _column_iter(_TPtr base, int ds, bool r, int rw) :
+      _matrix_iter<_TRef, _TPtr>(base, ds, r), row(rw) {};
+  _Self&
   operator++() override
   {
     _Tparent::ptr++;
@@ -284,7 +286,7 @@ public:
     if (_Tparent::real)
       return *(_Tparent::ptr);
     else
-      return *(_Tparent::ptr+_Tparent::d_size);
+      return *(_Tparent::ptr + _Tparent::d_size);
   }
   int
   getRow() const
@@ -299,12 +301,11 @@ class _row_iter : public _matrix_iter<_TRef, _TPtr>
   using _Tparent = _matrix_iter<_TRef, _TPtr>;
   using _Self = _row_iter<_TRef, _TPtr>;
   int col;
+
 public:
-  _row_iter(_TPtr base, int ds, bool r, int cl)
-    : _matrix_iter<_TRef, _TPtr>(base, ds, r), col(cl)
-  {
-  };
-  _Self &
+  _row_iter(_TPtr base, int ds, bool r, int cl) :
+      _matrix_iter<_TRef, _TPtr>(base, ds, r), col(cl) {};
+  _Self&
   operator++() override
   {
     _Tparent::ptr += _Tparent::d_size;
@@ -317,7 +318,7 @@ public:
     if (_Tparent::real)
       return *(_Tparent::ptr);
     else
-      return *(_Tparent::ptr+1);
+      return *(_Tparent::ptr + 1);
   }
   int
   getCol() const
@@ -338,29 +339,30 @@ class SchurDecompZero;
 class QuasiTriangular : public SqSylvMatrix
 {
 public:
-  using const_col_iter = _column_iter<const double &, const double *>;
-  using col_iter = _column_iter<double &, double *>;
-  using const_row_iter = _row_iter<const double &, const double *>;
-  using row_iter = _row_iter<double &, double *>;
+  using const_col_iter = _column_iter<const double&, const double*>;
+  using col_iter = _column_iter<double&, double*>;
+  using const_row_iter = _row_iter<const double&, const double*>;
+  using row_iter = _row_iter<double&, double*>;
   using const_diag_iter = Diagonal::const_diag_iter;
   using diag_iter = Diagonal::diag_iter;
+
 protected:
   Diagonal diagonal;
+
 public:
-  QuasiTriangular(const ConstVector &d, int d_size);
+  QuasiTriangular(const ConstVector& d, int d_size);
   // Initializes with r·t
-  QuasiTriangular(double r, const QuasiTriangular &t);
+  QuasiTriangular(double r, const QuasiTriangular& t);
   // Initializes with r·t+r₂·t₂
-  QuasiTriangular(double r, const QuasiTriangular &t,
-                  double r2, const QuasiTriangular &t2);
+  QuasiTriangular(double r, const QuasiTriangular& t, double r2, const QuasiTriangular& t2);
   // Initializes with t²
-  QuasiTriangular(const std::string &dummy, const QuasiTriangular &t);
-  explicit QuasiTriangular(const SchurDecomp &decomp);
-  explicit QuasiTriangular(const SchurDecompZero &decomp);
-  QuasiTriangular(const QuasiTriangular &t);
+  QuasiTriangular(const std::string& dummy, const QuasiTriangular& t);
+  explicit QuasiTriangular(const SchurDecomp& decomp);
+  explicit QuasiTriangular(const SchurDecompZero& decomp);
+  QuasiTriangular(const QuasiTriangular& t);
 
   ~QuasiTriangular() override = default;
-  const Diagonal &
+  const Diagonal&
   getDiagonal() const
   {
     return diagonal;
@@ -373,29 +375,29 @@ public:
   diag_iter findNextLargerBlock(diag_iter start, diag_iter end, double a);
 
   /* (I+this)·y = x, y→x  */
-  virtual void solvePre(Vector &x, double &eig_min);
+  virtual void solvePre(Vector& x, double& eig_min);
   /* (I+thisᵀ)·y = x, y→x */
-  virtual void solvePreTrans(Vector &x, double &eig_min);
+  virtual void solvePreTrans(Vector& x, double& eig_min);
   /* (I+this)·x = b */
-  virtual void solve(Vector &x, const ConstVector &b, double &eig_min);
+  virtual void solve(Vector& x, const ConstVector& b, double& eig_min);
   /* (I+thisᵀ)·x = b */
-  virtual void solveTrans(Vector &x, const ConstVector &b, double &eig_min);
+  virtual void solveTrans(Vector& x, const ConstVector& b, double& eig_min);
   /* x = this·b */
-  virtual void multVec(Vector &x, const ConstVector &b) const;
+  virtual void multVec(Vector& x, const ConstVector& b) const;
   /* x = thisᵀ·b */
-  virtual void multVecTrans(Vector &x, const ConstVector &b) const;
+  virtual void multVecTrans(Vector& x, const ConstVector& b) const;
   /* x = x + this·b */
-  virtual void multaVec(Vector &x, const ConstVector &b) const;
+  virtual void multaVec(Vector& x, const ConstVector& b) const;
   /* x = x + thisᵀ·b */
-  virtual void multaVecTrans(Vector &x, const ConstVector &b) const;
+  virtual void multaVecTrans(Vector& x, const ConstVector& b) const;
   /* x = (this⊗I)·x */
-  virtual void multKron(KronVector &x) const;
+  virtual void multKron(KronVector& x) const;
   /* x = (thisᵀ⊗I)·x */
-  virtual void multKronTrans(KronVector &x) const;
+  virtual void multKronTrans(KronVector& x) const;
   /* A = this·A */
-  virtual void multLeftOther(GeneralMatrix &a) const;
+  virtual void multLeftOther(GeneralMatrix& a) const;
   /* A = thisᵀ·A */
-  virtual void multLeftOtherTrans(GeneralMatrix &a) const;
+  virtual void multLeftOtherTrans(GeneralMatrix& a) const;
 
   const_diag_iter
   diag_begin() const
@@ -419,14 +421,14 @@ public:
   }
 
   /* iterators for off diagonal elements */
-  virtual const_col_iter col_begin(const DiagonalBlock &b) const;
-  virtual col_iter col_begin(const DiagonalBlock &b);
-  virtual const_row_iter row_begin(const DiagonalBlock &b) const;
-  virtual row_iter row_begin(const DiagonalBlock &b);
-  virtual const_col_iter col_end(const DiagonalBlock &b) const;
-  virtual col_iter col_end(const DiagonalBlock &b);
-  virtual const_row_iter row_end(const DiagonalBlock &b) const;
-  virtual row_iter row_end(const DiagonalBlock &b);
+  virtual const_col_iter col_begin(const DiagonalBlock& b) const;
+  virtual col_iter col_begin(const DiagonalBlock& b);
+  virtual const_row_iter row_begin(const DiagonalBlock& b) const;
+  virtual row_iter row_begin(const DiagonalBlock& b);
+  virtual const_col_iter col_end(const DiagonalBlock& b) const;
+  virtual col_iter col_end(const DiagonalBlock& b);
+  virtual const_row_iter row_end(const DiagonalBlock& b) const;
+  virtual row_iter row_end(const DiagonalBlock& b);
 
   virtual std::unique_ptr<QuasiTriangular>
   clone() const
@@ -447,25 +449,27 @@ public:
   }
   // Returns r·this + r₂·t₂
   virtual std::unique_ptr<QuasiTriangular>
-  linearlyCombine(double r, double r2, const QuasiTriangular &t2) const
+  linearlyCombine(double r, double r2, const QuasiTriangular& t2) const
   {
     return std::make_unique<QuasiTriangular>(r, *this, r2, t2);
   }
+
 protected:
   // this = r·t
-  void setMatrix(double r, const QuasiTriangular &t);
+  void setMatrix(double r, const QuasiTriangular& t);
   // this = this + r·t
-  void addMatrix(double r, const QuasiTriangular &t);
+  void addMatrix(double r, const QuasiTriangular& t);
+
 private:
   // this = this + I
   void addUnit();
   /* x = x + (this⊗I)·b */
-  void multaKron(KronVector &x, const ConstKronVector &b) const;
+  void multaKron(KronVector& x, const ConstKronVector& b) const;
   /* x = x + (thisᵀ⊗I)·b */
-  void multaKronTrans(KronVector &x, const ConstKronVector &b) const;
+  void multaKronTrans(KronVector& x, const ConstKronVector& b) const;
   /* hide noneffective implementations of parents */
-  void multsVec(Vector &x, const ConstVector &d) const;
-  void multsVecTrans(Vector &x, const ConstVector &d) const;
+  void multsVec(Vector& x, const ConstVector& d) const;
+  void multsVecTrans(Vector& x, const ConstVector& d) const;
 };
 
 #endif /* QUASI_TRIANGULAR_H */
diff --git a/mex/sources/libkorder/sylv/QuasiTriangularZero.cc b/mex/sources/libkorder/sylv/QuasiTriangularZero.cc
index c093e857f526fa0eeca91b9639076ab64421780a..1e43924a84d1fcdcce7419ee7a1b68b0c193a86b 100644
--- a/mex/sources/libkorder/sylv/QuasiTriangularZero.cc
+++ b/mex/sources/libkorder/sylv/QuasiTriangularZero.cc
@@ -20,69 +20,58 @@
 
 #include "QuasiTriangularZero.hh"
 #include "SchurDecomp.hh"
-#include "SylvMatrix.hh"
 #include "SylvException.hh"
+#include "SylvMatrix.hh"
 
 #include <iostream>
 
-QuasiTriangularZero::QuasiTriangularZero(int num_zeros, const ConstVector &d,
-                                         int d_size)
-  : QuasiTriangular(SqSylvMatrix(GeneralMatrix(Vector{d}, num_zeros+d_size, d_size),
-                                 num_zeros, 0, d_size).getData(),
-                    d_size),
+QuasiTriangularZero::QuasiTriangularZero(int num_zeros, const ConstVector& d, int d_size) :
+    QuasiTriangular(
+        SqSylvMatrix(GeneralMatrix(Vector {d}, num_zeros + d_size, d_size), num_zeros, 0, d_size)
+            .getData(),
+        d_size),
     nz(num_zeros),
-    ru(GeneralMatrix(Vector{d}, num_zeros+d_size, d_size), 0, 0, num_zeros, d_size)
+    ru(GeneralMatrix(Vector {d}, num_zeros + d_size, d_size), 0, 0, num_zeros, d_size)
 {
 }
 
-QuasiTriangularZero::QuasiTriangularZero(double r,
-                                         const QuasiTriangularZero &t)
-  : QuasiTriangular(r, t),
-    nz(t.nz),
-    ru(t.ru)
+QuasiTriangularZero::QuasiTriangularZero(double r, const QuasiTriangularZero& t) :
+    QuasiTriangular(r, t), nz(t.nz), ru(t.ru)
 {
   ru.mult(r);
 }
 
-QuasiTriangularZero::QuasiTriangularZero(double r,
-                                         const QuasiTriangularZero &t,
-                                         double r2,
-                                         const QuasiTriangularZero &t2)
-  : QuasiTriangular(r, t, r2, t2),
-    nz(t.nz),
-    ru(t.ru)
+QuasiTriangularZero::QuasiTriangularZero(double r, const QuasiTriangularZero& t, double r2,
+                                         const QuasiTriangularZero& t2) :
+    QuasiTriangular(r, t, r2, t2),
+    nz(t.nz), ru(t.ru)
 {
   ru.mult(r);
   ru.add(r2, t2.ru);
 }
 
-QuasiTriangularZero::QuasiTriangularZero(const std::string &dummy, const QuasiTriangularZero &t)
-  : QuasiTriangular(dummy, t),
-    nz(t.nz),
-    ru(t.ru)
+QuasiTriangularZero::QuasiTriangularZero(const std::string& dummy, const QuasiTriangularZero& t) :
+    QuasiTriangular(dummy, t), nz(t.nz), ru(t.ru)
 {
   ru.multRight(t);
 }
 
-QuasiTriangularZero::QuasiTriangularZero(const SchurDecompZero &decomp)
-  : QuasiTriangular(decomp.getT().getData(),
-                    decomp.getT().nrows()),
-    nz(decomp.getZeroCols()),
+QuasiTriangularZero::QuasiTriangularZero(const SchurDecompZero& decomp) :
+    QuasiTriangular(decomp.getT().getData(), decomp.getT().nrows()), nz(decomp.getZeroCols()),
     ru(decomp.getRU())
 {
 }
 
-QuasiTriangularZero::QuasiTriangularZero(const QuasiTriangular &t)
-  : QuasiTriangular(t),
-    nz(0), ru(0, t.getDiagonal().getSize())
+QuasiTriangularZero::QuasiTriangularZero(const QuasiTriangular& t) :
+    QuasiTriangular(t), nz(0), ru(0, t.getDiagonal().getSize())
 {
 }
 
 void
-QuasiTriangularZero::solvePre(Vector &x, double &eig_min)
+QuasiTriangularZero::solvePre(Vector& x, double& eig_min)
 {
   Vector xu(x, 0, nz);
-  Vector xl(x, nz, x.length()-nz);
+  Vector xl(x, nz, x.length() - nz);
   QuasiTriangular::solvePre(xl, eig_min);
   ru.multsVec(xu, xl);
   if (nz > 0)
@@ -90,10 +79,10 @@ QuasiTriangularZero::solvePre(Vector &x, double &eig_min)
 }
 
 void
-QuasiTriangularZero::solvePreTrans(Vector &x, double &eig_min)
+QuasiTriangularZero::solvePreTrans(Vector& x, double& eig_min)
 {
   Vector xu(x, 0, nz);
-  Vector xl(x, nz, x.length()-nz);
+  Vector xl(x, nz, x.length() - nz);
   ru.multsVecTrans(xl, xu);
   QuasiTriangular::solvePreTrans(xl, eig_min);
   if (nz > 0)
@@ -101,47 +90,47 @@ QuasiTriangularZero::solvePreTrans(Vector &x, double &eig_min)
 }
 
 void
-QuasiTriangularZero::multVec(Vector &x, const ConstVector &b) const
+QuasiTriangularZero::multVec(Vector& x, const ConstVector& b) const
 {
   x.zeros();
   multaVec(x, b);
 }
 
 void
-QuasiTriangularZero::multVecTrans(Vector &x, const ConstVector &b) const
+QuasiTriangularZero::multVecTrans(Vector& x, const ConstVector& b) const
 {
   x.zeros();
   multaVecTrans(x, b);
 }
 
 void
-QuasiTriangularZero::multaVec(Vector &x, const ConstVector &b) const
+QuasiTriangularZero::multaVec(Vector& x, const ConstVector& b) const
 {
-  ConstVector bl(b, nz, b.length()-nz);
+  ConstVector bl(b, nz, b.length() - nz);
   Vector xu(x, 0, nz);
-  Vector xl(x, nz, x.length()-nz);
+  Vector xl(x, nz, x.length() - nz);
   xu.zeros();
   ru.multaVec(xu, bl);
   QuasiTriangular::multVec(xl, bl);
 }
 
 void
-QuasiTriangularZero::multaVecTrans(Vector &x, const ConstVector &b) const
+QuasiTriangularZero::multaVecTrans(Vector& x, const ConstVector& b) const
 {
   ConstVector bu(b, 0, b.length());
-  ConstVector bl(b, nz, b.length()-nz);
+  ConstVector bl(b, nz, b.length() - nz);
   Vector xu(x, 0, nz);
-  Vector xl(x, nz, x.length()-nz);
+  Vector xl(x, nz, x.length() - nz);
   xu.zeros();
   QuasiTriangular::multVecTrans(xl, bl);
   ru.multaVecTrans(xl, bu);
 }
 
 void
-QuasiTriangularZero::multLeftOther(GeneralMatrix &a) const
+QuasiTriangularZero::multLeftOther(GeneralMatrix& a) const
 {
   GeneralMatrix a1(a, 0, 0, nz, a.ncols());
-  GeneralMatrix a2(a, nz, 0, a.nrows()-nz, a.ncols());
+  GeneralMatrix a2(a, nz, 0, a.nrows() - nz, a.ncols());
   a1.mult(ru, a2);
   QuasiTriangular::multLeftOther(a2);
 }
@@ -151,19 +140,18 @@ QuasiTriangularZero::print() const
 {
   std::cout << "super=" << std::endl;
   QuasiTriangular::print();
-  std::cout << "nz=" << nz << std::endl
-            << "ru=" << std::endl;
+  std::cout << "nz=" << nz << std::endl << "ru=" << std::endl;
   ru.print();
 }
 
 void
-QuasiTriangularZero::multKron([[maybe_unused]] KronVector &x) const
+QuasiTriangularZero::multKron([[maybe_unused]] KronVector& x) const
 {
   throw SYLV_MES_EXCEPTION("Attempt to run QuasiTriangularZero::multKron.");
 }
 
 void
-QuasiTriangularZero::multKronTrans([[maybe_unused]] KronVector &x) const
+QuasiTriangularZero::multKronTrans([[maybe_unused]] KronVector& x) const
 {
   throw SYLV_MES_EXCEPTION("Attempt to run QuasiTriangularZero::multKronTrans.");
 }
diff --git a/mex/sources/libkorder/sylv/QuasiTriangularZero.hh b/mex/sources/libkorder/sylv/QuasiTriangularZero.hh
index 831c6c5e47074ada0dafa1e19d7308597b3e0d9e..fd9767b3a9caeb8c1dec682b289dd9a0a4ec40e4 100644
--- a/mex/sources/libkorder/sylv/QuasiTriangularZero.hh
+++ b/mex/sources/libkorder/sylv/QuasiTriangularZero.hh
@@ -21,8 +21,8 @@
 #ifndef QUASI_TRIANGULAR_ZERO_H
 #define QUASI_TRIANGULAR_ZERO_H
 
-#include "QuasiTriangular.hh"
 #include "GeneralMatrix.hh"
+#include "QuasiTriangular.hh"
 
 #include <memory>
 
@@ -36,29 +36,29 @@
 
 class QuasiTriangularZero : public QuasiTriangular
 {
-  int nz; // number of zero columns
+  int nz;           // number of zero columns
   GeneralMatrix ru; // data in right upper part (of size nz×d_size)
 public:
-  QuasiTriangularZero(int num_zeros, const ConstVector &d, int d_size);
+  QuasiTriangularZero(int num_zeros, const ConstVector& d, int d_size);
   // Initializes with r·t
-  QuasiTriangularZero(double r, const QuasiTriangularZero &t);
+  QuasiTriangularZero(double r, const QuasiTriangularZero& t);
   // Initializes with r·t+r₂·t₂
-  QuasiTriangularZero(double r, const QuasiTriangularZero &t,
-                      double r2, const QuasiTriangularZero &t2);
+  QuasiTriangularZero(double r, const QuasiTriangularZero& t, double r2,
+                      const QuasiTriangularZero& t2);
   // Initializes with t²
-  QuasiTriangularZero(const std::string &dummy, const QuasiTriangularZero &t);
-  explicit QuasiTriangularZero(const QuasiTriangular &t);
-  explicit QuasiTriangularZero(const SchurDecompZero &decomp);
+  QuasiTriangularZero(const std::string& dummy, const QuasiTriangularZero& t);
+  explicit QuasiTriangularZero(const QuasiTriangular& t);
+  explicit QuasiTriangularZero(const SchurDecompZero& decomp);
   ~QuasiTriangularZero() override = default;
-  void solvePre(Vector &x, double &eig_min) override;
-  void solvePreTrans(Vector &x, double &eig_min) override;
-  void multVec(Vector &x, const ConstVector &b) const override;
-  void multVecTrans(Vector &x, const ConstVector &b) const override;
-  void multaVec(Vector &x, const ConstVector &b) const override;
-  void multaVecTrans(Vector &x, const ConstVector &b) const override;
-  void multKron(KronVector &x) const override;
-  void multKronTrans(KronVector &x) const override;
-  void multLeftOther(GeneralMatrix &a) const override;
+  void solvePre(Vector& x, double& eig_min) override;
+  void solvePreTrans(Vector& x, double& eig_min) override;
+  void multVec(Vector& x, const ConstVector& b) const override;
+  void multVecTrans(Vector& x, const ConstVector& b) const override;
+  void multaVec(Vector& x, const ConstVector& b) const override;
+  void multaVecTrans(Vector& x, const ConstVector& b) const override;
+  void multKron(KronVector& x) const override;
+  void multKronTrans(KronVector& x) const override;
+  void multLeftOther(GeneralMatrix& a) const override;
 
   std::unique_ptr<QuasiTriangular>
   clone() const override
@@ -76,9 +76,10 @@ public:
     return std::make_unique<QuasiTriangularZero>(r, *this);
   }
   std::unique_ptr<QuasiTriangular>
-  linearlyCombine(double r, double r2, const QuasiTriangular &t2) const override
+  linearlyCombine(double r, double r2, const QuasiTriangular& t2) const override
   {
-    return std::make_unique<QuasiTriangularZero>(r, *this, r2, dynamic_cast<const QuasiTriangularZero &>(t2));
+    return std::make_unique<QuasiTriangularZero>(r, *this, r2,
+                                                 dynamic_cast<const QuasiTriangularZero&>(t2));
   }
   void print() const override;
 };
diff --git a/mex/sources/libkorder/sylv/SchurDecomp.cc b/mex/sources/libkorder/sylv/SchurDecomp.cc
index 6ce30157913b0386a8d75cebe84306bde1eec6cd..a10e3fea762a251380c9cb25e335e41a699d7afa 100644
--- a/mex/sources/libkorder/sylv/SchurDecomp.cc
+++ b/mex/sources/libkorder/sylv/SchurDecomp.cc
@@ -24,8 +24,7 @@
 
 #include <dynlapack.h>
 
-SchurDecomp::SchurDecomp(const SqSylvMatrix &m)
-  : q(m.nrows())
+SchurDecomp::SchurDecomp(const SqSylvMatrix& m) : q(m.nrows())
 {
   lapack_int rows = m.nrows();
   SqSylvMatrix auxt(m);
@@ -33,24 +32,22 @@ SchurDecomp::SchurDecomp(const SqSylvMatrix &m)
   lapack_int sdim;
   auto wr = std::make_unique<double[]>(rows);
   auto wi = std::make_unique<double[]>(rows);
-  lapack_int lwork = 6*rows;
+  lapack_int lwork = 6 * rows;
   auto work = std::make_unique<double[]>(lwork);
   lapack_int info;
-  dgees("V", "N", nullptr, &rows, auxt.base(), &lda, &sdim,
-        wr.get(), wi.get(), q.base(), &ldvs,
+  dgees("V", "N", nullptr, &rows, auxt.base(), &lda, &sdim, wr.get(), wi.get(), q.base(), &ldvs,
         work.get(), &lwork, nullptr, &info);
   t_storage = std::make_unique<QuasiTriangular>(auxt.getData(), rows);
   t = t_storage.get();
 }
 
-SchurDecomp::SchurDecomp(const QuasiTriangular &tr)
-  : q(tr.nrows()), t_storage{std::make_unique<QuasiTriangular>(tr)}, t{t_storage.get()}
+SchurDecomp::SchurDecomp(const QuasiTriangular& tr) :
+    q(tr.nrows()), t_storage {std::make_unique<QuasiTriangular>(tr)}, t {t_storage.get()}
 {
   q.setUnit();
 }
 
-SchurDecomp::SchurDecomp(QuasiTriangular &tr)
-  : q(tr.nrows()), t{&tr}
+SchurDecomp::SchurDecomp(QuasiTriangular& tr) : q(tr.nrows()), t {&tr}
 {
   q.setUnit();
 }
@@ -61,9 +58,9 @@ SchurDecomp::getDim() const
   return t->nrows();
 }
 
-SchurDecompZero::SchurDecompZero(const GeneralMatrix &m)
-  : SchurDecomp(SqSylvMatrix(m, m.nrows()-m.ncols(), 0, m.ncols())),
-    ru(m, 0, 0, m.nrows()-m.ncols(), m.ncols())
+SchurDecompZero::SchurDecompZero(const GeneralMatrix& m) :
+    SchurDecomp(SqSylvMatrix(m, m.nrows() - m.ncols(), 0, m.ncols())),
+    ru(m, 0, 0, m.nrows() - m.ncols(), m.ncols())
 {
   ru.multRight(getQ());
 }
@@ -71,5 +68,5 @@ SchurDecompZero::SchurDecompZero(const GeneralMatrix &m)
 int
 SchurDecompZero::getDim() const
 {
-  return getT().nrows()+ru.nrows();
+  return getT().nrows() + ru.nrows();
 }
diff --git a/mex/sources/libkorder/sylv/SchurDecomp.hh b/mex/sources/libkorder/sylv/SchurDecomp.hh
index d7a076240e815dcfd861c1448351e020f994450a..743fa3c2068d47ec06ca10f0c523dad837c94093 100644
--- a/mex/sources/libkorder/sylv/SchurDecomp.hh
+++ b/mex/sources/libkorder/sylv/SchurDecomp.hh
@@ -21,8 +21,8 @@
 #ifndef SCHUR_DECOMP_H
 #define SCHUR_DECOMP_H
 
-#include "SylvMatrix.hh"
 #include "QuasiTriangular.hh"
+#include "SylvMatrix.hh"
 
 #include <memory>
 
@@ -32,27 +32,28 @@ class SchurDecomp
   SqSylvMatrix q;
   // Stores t if is owned
   std::unique_ptr<QuasiTriangular> t_storage;
-  QuasiTriangular *t;
+  QuasiTriangular* t;
+
 public:
-  SchurDecomp(const SqSylvMatrix &m);
-  SchurDecomp(const QuasiTriangular &tr);
-  SchurDecomp(QuasiTriangular &tr);
-  const SqSylvMatrix &
+  SchurDecomp(const SqSylvMatrix& m);
+  SchurDecomp(const QuasiTriangular& tr);
+  SchurDecomp(QuasiTriangular& tr);
+  const SqSylvMatrix&
   getQ() const
   {
     return q;
   }
-  const QuasiTriangular &
+  const QuasiTriangular&
   getT() const
   {
     return *t;
   }
-  SqSylvMatrix &
+  SqSylvMatrix&
   getQ()
   {
     return q;
   }
-  QuasiTriangular &
+  QuasiTriangular&
   getT()
   {
     return *t;
@@ -65,7 +66,7 @@ class SchurDecompZero : public SchurDecomp
 {
   GeneralMatrix ru; // right upper matrix
 public:
-  SchurDecompZero(const GeneralMatrix &m);
+  SchurDecompZero(const GeneralMatrix& m);
   ConstGeneralMatrix
   getRU() const
   {
diff --git a/mex/sources/libkorder/sylv/SchurDecompEig.cc b/mex/sources/libkorder/sylv/SchurDecompEig.cc
index 97bcd57defa428081f4651991b5ceb73482be170..ffa0de731a51b8f73639531f32cb906244ec846c 100644
--- a/mex/sources/libkorder/sylv/SchurDecompEig.cc
+++ b/mex/sources/libkorder/sylv/SchurDecompEig.cc
@@ -67,7 +67,7 @@ SchurDecompEig::bubbleEigen(diag_iter from, diag_iter to)
    The success is signaled by returned true.
 */
 bool
-SchurDecompEig::tryToSwap(diag_iter &it, diag_iter &itadd)
+SchurDecompEig::tryToSwap(diag_iter& it, diag_iter& itadd)
 {
   itadd = it;
   --itadd;
@@ -77,8 +77,7 @@ SchurDecompEig::tryToSwap(diag_iter &it, diag_iter &itadd)
   lapack_int ilst = itadd->getIndex() + 1;
   auto work = std::make_unique<double[]>(n);
   lapack_int info;
-  dtrexc("V", &n, getT().base(), &ldt, getQ().base(), &ldq, &ifst, &ilst, work.get(),
-         &info);
+  dtrexc("V", &n, getT().base(), &ldt, getQ().base(), &ldq, &ifst, &ilst, work.get(), &info);
   if (info < 0)
     throw SYLV_MES_EXCEPTION("Wrong argument to dtrexc.");
 
@@ -105,8 +104,7 @@ SchurDecompEig::orderEigen()
   double last_size = 0.0;
   while (runp != getT().diag_end())
     {
-      diag_iter least = getT().findNextLargerBlock(run, getT().diag_end(),
-                                                   last_size);
+      diag_iter least = getT().findNextLargerBlock(run, getT().diag_end(), last_size);
       last_size = least->getSize();
       if (run == least)
         ++run;
diff --git a/mex/sources/libkorder/sylv/SchurDecompEig.hh b/mex/sources/libkorder/sylv/SchurDecompEig.hh
index 57e8f1ba3a9ca4fa5af79989a89b16cfc1d3bfe2..63967d769bd1bb756b9aebc0983f0efedf541a9a 100644
--- a/mex/sources/libkorder/sylv/SchurDecompEig.hh
+++ b/mex/sources/libkorder/sylv/SchurDecompEig.hh
@@ -23,26 +23,25 @@
 #ifndef SCHUR_DECOMP_EIG_H
 #define SCHUR_DECOMP_EIG_H
 
-#include "SchurDecomp.hh"
 #include "QuasiTriangular.hh"
+#include "SchurDecomp.hh"
 
 class SchurDecompEig : public SchurDecomp
 {
 public:
   using diag_iter = QuasiTriangular::diag_iter;
-  SchurDecompEig(const SqSylvMatrix &m) : SchurDecomp(m)
+  SchurDecompEig(const SqSylvMatrix& m) : SchurDecomp(m)
   {
   }
-  SchurDecompEig(const QuasiTriangular &tr) : SchurDecomp(tr)
-  {
-  };
-  SchurDecompEig(QuasiTriangular &tr) : SchurDecomp(tr)
+  SchurDecompEig(const QuasiTriangular& tr) : SchurDecomp(tr) {};
+  SchurDecompEig(QuasiTriangular& tr) : SchurDecomp(tr)
   {
   }
   diag_iter bubbleEigen(diag_iter from, diag_iter to);
   void orderEigen();
+
 protected:
-  bool tryToSwap(diag_iter &it, diag_iter &itadd);
+  bool tryToSwap(diag_iter& it, diag_iter& itadd);
 };
 
 #endif /* SCHUR_DECOMP_EIG_H */
diff --git a/mex/sources/libkorder/sylv/SimilarityDecomp.cc b/mex/sources/libkorder/sylv/SimilarityDecomp.cc
index 62bec28f12609fbb4915cf6d2cce4d768a6c310a..d61cadbfd726e0f5fac96ee20ee8659b3486941a 100644
--- a/mex/sources/libkorder/sylv/SimilarityDecomp.cc
+++ b/mex/sources/libkorder/sylv/SimilarityDecomp.cc
@@ -27,9 +27,9 @@
 
 #include <cmath>
 
-SimilarityDecomp::SimilarityDecomp(const ConstVector &d, int d_size, double log10norm)
+SimilarityDecomp::SimilarityDecomp(const ConstVector& d, int d_size, double log10norm)
 {
-  SchurDecomp sd(SqSylvMatrix(Vector{d}, d_size));
+  SchurDecomp sd(SqSylvMatrix(Vector {d}, d_size));
   q = std::make_unique<SqSylvMatrix>(sd.getQ());
   b = std::make_unique<BlockDiagonal>(sd.getT());
   invq = std::make_unique<SqSylvMatrix>(d_size);
@@ -40,8 +40,7 @@ SimilarityDecomp::SimilarityDecomp(const ConstVector &d, int d_size, double log1
 }
 
 void
-SimilarityDecomp::getXDim(diag_iter start, diag_iter end,
-                          int &rows, int &cols) const
+SimilarityDecomp::getXDim(diag_iter start, diag_iter end, int& rows, int& cols) const
 {
   int si = start->getIndex();
   int ei = end->getIndex();
@@ -54,15 +53,14 @@ SimilarityDecomp::getXDim(diag_iter start, diag_iter end,
    norm, X is not changed and flase is returned.
 */
 bool
-SimilarityDecomp::solveX(diag_iter start, diag_iter end,
-                         GeneralMatrix &X, double norm) const
+SimilarityDecomp::solveX(diag_iter start, diag_iter end, GeneralMatrix& X, double norm) const
 {
   int si = start->getIndex();
   int ei = end->getIndex();
 
-  SqSylvMatrix A(const_cast<const BlockDiagonal &>(*b), si, si, X.nrows());
-  SqSylvMatrix B(const_cast<const BlockDiagonal &>(*b), ei, ei, X.ncols());
-  GeneralMatrix C(const_cast<const BlockDiagonal &>(*b), si, ei, X.nrows(), X.ncols());
+  SqSylvMatrix A(const_cast<const BlockDiagonal&>(*b), si, si, X.nrows());
+  SqSylvMatrix B(const_cast<const BlockDiagonal&>(*b), ei, ei, X.ncols());
+  GeneralMatrix C(const_cast<const BlockDiagonal&>(*b), si, ei, X.nrows(), X.ncols());
 
   lapack_int isgn = -1;
   lapack_int m = A.nrows();
@@ -70,8 +68,7 @@ SimilarityDecomp::solveX(diag_iter start, diag_iter end,
   lapack_int lda = A.getLD(), ldb = B.getLD();
   double scale;
   lapack_int info;
-  dtrsyl("N", "N", &isgn, &m, &n, A.base(), &lda, B.base(), &ldb,
-         C.base(), &m, &scale, &info);
+  dtrsyl("N", "N", &isgn, &m, &n, A.base(), &lda, B.base(), &ldb, C.base(), &m, &scale, &info);
   if (info < -1)
     throw SYLV_MES_EXCEPTION("Wrong parameter to LAPACK dtrsyl.");
 
@@ -87,8 +84,7 @@ SimilarityDecomp::solveX(diag_iter start, diag_iter end,
 /*                         ⎛I −X⎞     ⎛I X⎞
   Multiply Q and invQ with ⎝0  I⎠ and ⎝0 I⎠ respectively. This also sets X=−X. */
 void
-SimilarityDecomp::updateTransform(diag_iter start, diag_iter end,
-                                  GeneralMatrix &X)
+SimilarityDecomp::updateTransform(diag_iter start, diag_iter end, GeneralMatrix& X)
 {
   int si = start->getIndex();
   int ei = end->getIndex();
@@ -105,11 +101,11 @@ SimilarityDecomp::updateTransform(diag_iter start, diag_iter end,
 }
 
 void
-SimilarityDecomp::bringGuiltyBlock(diag_iter start, diag_iter &end)
+SimilarityDecomp::bringGuiltyBlock(diag_iter start, diag_iter& end)
 {
   double av = b->getAverageDiagSize(start, end);
   diag_iter guilty = b->findClosestDiagBlock(end, b->diag_end(), av);
-  SchurDecompEig sd(*b); // works on b including diagonal structure
+  SchurDecompEig sd(*b);             // works on b including diagonal structure
   end = sd.bubbleEigen(guilty, end); // iterators are valid
   ++end;
   q->multRight(sd.getQ());
@@ -142,7 +138,7 @@ SimilarityDecomp::diagonalize(double norm)
 }
 
 void
-SimilarityDecomp::check(SylvParams &pars, const GeneralMatrix &m) const
+SimilarityDecomp::check(SylvParams& pars, const GeneralMatrix& m) const
 {
   // M − Q·B·Q⁻¹
   SqSylvMatrix c(getQ() * getB());
@@ -167,7 +163,7 @@ SimilarityDecomp::check(SylvParams &pars, const GeneralMatrix &m) const
 }
 
 void
-SimilarityDecomp::infoToPars(SylvParams &pars) const
+SimilarityDecomp::infoToPars(SylvParams& pars) const
 {
   pars.f_blocks = getB().getNumBlocks();
   pars.f_largest = getB().getLargestBlock();
diff --git a/mex/sources/libkorder/sylv/SimilarityDecomp.hh b/mex/sources/libkorder/sylv/SimilarityDecomp.hh
index 8cf21ee32e557609839c3b32938079b1ec63e6fc..2e9b70c7bbb071f1fbe953553820bbbeef59af46 100644
--- a/mex/sources/libkorder/sylv/SimilarityDecomp.hh
+++ b/mex/sources/libkorder/sylv/SimilarityDecomp.hh
@@ -21,8 +21,8 @@
 #ifndef SIMILARITY_DECOMP_H
 #define SIMILARITY_DECOMP_H
 
-#include "SylvMatrix.hh"
 #include "BlockDiagonal.hh"
+#include "SylvMatrix.hh"
 #include "SylvParams.hh"
 
 #include <memory>
@@ -33,31 +33,33 @@ class SimilarityDecomp
   std::unique_ptr<BlockDiagonal> b;
   std::unique_ptr<SqSylvMatrix> invq;
   using diag_iter = BlockDiagonal::diag_iter;
+
 public:
-  SimilarityDecomp(const ConstVector &d, int d_size, double log10norm = 3.0);
+  SimilarityDecomp(const ConstVector& d, int d_size, double log10norm = 3.0);
   virtual ~SimilarityDecomp() = default;
-  const SqSylvMatrix &
+  const SqSylvMatrix&
   getQ() const
   {
     return *q;
   }
-  const SqSylvMatrix &
+  const SqSylvMatrix&
   getInvQ() const
   {
     return *invq;
   }
-  const BlockDiagonal &
+  const BlockDiagonal&
   getB() const
   {
     return *b;
   }
-  void check(SylvParams &pars, const GeneralMatrix &m) const;
-  void infoToPars(SylvParams &pars) const;
+  void check(SylvParams& pars, const GeneralMatrix& m) const;
+  void infoToPars(SylvParams& pars) const;
+
 protected:
-  void getXDim(diag_iter start, diag_iter end, int &rows, int &cols) const;
-  bool solveX(diag_iter start, diag_iter end, GeneralMatrix &X, double norm) const;
-  void updateTransform(diag_iter start, diag_iter end, GeneralMatrix &X);
-  void bringGuiltyBlock(diag_iter start, diag_iter &end);
+  void getXDim(diag_iter start, diag_iter end, int& rows, int& cols) const;
+  bool solveX(diag_iter start, diag_iter end, GeneralMatrix& X, double norm) const;
+  void updateTransform(diag_iter start, diag_iter end, GeneralMatrix& X);
+  void bringGuiltyBlock(diag_iter start, diag_iter& end);
   void diagonalize(double norm);
 };
 
diff --git a/mex/sources/libkorder/sylv/SylvException.cc b/mex/sources/libkorder/sylv/SylvException.cc
index 70ecbc24b104451bf496f7fd0d8d06a644bf4748..8d786cfdd7cfa808725779546a34eb229f137281 100644
--- a/mex/sources/libkorder/sylv/SylvException.cc
+++ b/mex/sources/libkorder/sylv/SylvException.cc
@@ -23,8 +23,7 @@
 #include <iostream>
 #include <utility>
 
-SylvException::SylvException(std::string f, int l)
-  : file{std::move(f)}, line{l}
+SylvException::SylvException(std::string f, int l) : file {std::move(f)}, line {l}
 {
 }
 
@@ -40,9 +39,8 @@ SylvException::getMessage() const
   return "From " + file + ':' + std::to_string(line) + '\n';
 }
 
-SylvExceptionMessage::SylvExceptionMessage(std::string f, int i,
-                                           std::string mes)
-  : SylvException{std::move(f), i}, message{std::move(mes)}
+SylvExceptionMessage::SylvExceptionMessage(std::string f, int i, std::string mes) :
+    SylvException {std::move(f), i}, message {std::move(mes)}
 {
 }
 
diff --git a/mex/sources/libkorder/sylv/SylvException.hh b/mex/sources/libkorder/sylv/SylvException.hh
index 3fc1a16a4eaf9902494e9c6c2b4d74165cf84c1e..3c66541438bfd0bf0ec8b7893461679b434107c9 100644
--- a/mex/sources/libkorder/sylv/SylvException.hh
+++ b/mex/sources/libkorder/sylv/SylvException.hh
@@ -28,6 +28,7 @@ class SylvException
 protected:
   std::string file;
   int line;
+
 public:
   SylvException(std::string f, int l);
   virtual ~SylvException() = default;
@@ -38,6 +39,7 @@ public:
 class SylvExceptionMessage : public SylvException
 {
   std::string message;
+
 public:
   SylvExceptionMessage(std::string f, int l, std::string mes);
   std::string getMessage() const override;
diff --git a/mex/sources/libkorder/sylv/SylvMatrix.cc b/mex/sources/libkorder/sylv/SylvMatrix.cc
index cb4d8ba499bcaf993da6a4294aff25adfee04f01..65458f82c794352a246e297b435aafae492c7012 100644
--- a/mex/sources/libkorder/sylv/SylvMatrix.cc
+++ b/mex/sources/libkorder/sylv/SylvMatrix.cc
@@ -18,8 +18,8 @@
  * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#include "SylvException.hh"
 #include "SylvMatrix.hh"
+#include "SylvException.hh"
 #include "int_power.hh"
 
 #include <dynblas.h>
@@ -29,7 +29,7 @@
 #include <memory>
 
 void
-SylvMatrix::multLeftI(const SqSylvMatrix &m)
+SylvMatrix::multLeftI(const SqSylvMatrix& m)
 {
   int off = rows - m.nrows();
   if (off < 0)
@@ -40,7 +40,7 @@ SylvMatrix::multLeftI(const SqSylvMatrix &m)
 }
 
 void
-SylvMatrix::multLeftITrans(const SqSylvMatrix &m)
+SylvMatrix::multLeftITrans(const SqSylvMatrix& m)
 {
   int off = rows - m.nrows();
   if (off < 0)
@@ -51,11 +51,10 @@ SylvMatrix::multLeftITrans(const SqSylvMatrix &m)
 }
 
 void
-SylvMatrix::multLeft(int zero_cols, const GeneralMatrix &a, const GeneralMatrix &b)
+SylvMatrix::multLeft(int zero_cols, const GeneralMatrix& a, const GeneralMatrix& b)
 {
   int off = a.nrows() - a.ncols();
-  if (off < 0 || a.nrows() != rows || off != zero_cols
-      || rows != b.nrows() || cols != b.ncols())
+  if (off < 0 || a.nrows() != rows || off != zero_cols || rows != b.nrows() || cols != b.ncols())
     throw SYLV_MES_EXCEPTION("Wrong matrix dimensions for multLeft.");
 
   /* Here we cannot call SylvMatrix::gemm() since it would require
@@ -71,77 +70,77 @@ SylvMatrix::multLeft(int zero_cols, const GeneralMatrix &a, const GeneralMatrix
       blas_int ldb = ld;
       double beta = 0.0;
       blas_int ldc = ld;
-      dgemm("N", "N", &mm, &nn, &kk, &alpha, a.getData().base(), &lda,
-            b.getData().base()+off, &ldb, &beta, data.base(), &ldc);
+      dgemm("N", "N", &mm, &nn, &kk, &alpha, a.getData().base(), &lda, b.getData().base() + off,
+            &ldb, &beta, data.base(), &ldc);
     }
 }
 
 void
-SylvMatrix::multRightKron(const SqSylvMatrix &m, int order)
+SylvMatrix::multRightKron(const SqSylvMatrix& m, int order)
 {
   if (power(m.nrows(), order) != cols)
     throw SYLV_MES_EXCEPTION("Wrong number of cols for right kron multiply.");
 
-  KronVector auxrow(m.nrows(), m.nrows(), order-1);
+  KronVector auxrow(m.nrows(), m.nrows(), order - 1);
   for (int i = 0; i < rows; i++)
     {
-      Vector rowi{getRow(i)};
-      KronVector rowikron(rowi, m.nrows(), m.nrows(), order-1);
+      Vector rowi {getRow(i)};
+      KronVector rowikron(rowi, m.nrows(), m.nrows(), order - 1);
       auxrow = rowi; // copy data
       m.multVecKronTrans(rowikron, auxrow);
     }
 }
 
 void
-SylvMatrix::multRightKronTrans(const SqSylvMatrix &m, int order)
+SylvMatrix::multRightKronTrans(const SqSylvMatrix& m, int order)
 {
   if (power(m.nrows(), order) != cols)
     throw SYLV_MES_EXCEPTION("Wrong number of cols for right kron multiply.");
 
-  KronVector auxrow(m.nrows(), m.nrows(), order-1);
+  KronVector auxrow(m.nrows(), m.nrows(), order - 1);
   for (int i = 0; i < rows; i++)
     {
-      Vector rowi{getRow(i)};
-      KronVector rowikron(rowi, m.nrows(), m.nrows(), order-1);
+      Vector rowi {getRow(i)};
+      KronVector rowikron(rowi, m.nrows(), m.nrows(), order - 1);
       auxrow = rowi; // copy data
       m.multVecKron(rowikron, auxrow);
     }
 }
 
 void
-SylvMatrix::eliminateLeft(int row, int col, Vector &x)
+SylvMatrix::eliminateLeft(int row, int col, Vector& x)
 {
   double d = get(col, col);
   double e = get(row, col);
   if (std::abs(d) > std::abs(e))
     {
       get(row, col) = 0.0;
-      double mult = e/d;
+      double mult = e / d;
       for (int i = col + 1; i < ncols(); i++)
-        get(row, i) = get(row, i) - mult*get(col, i);
-      x[row] = x[row] - mult*x[col];
+        get(row, i) = get(row, i) - mult * get(col, i);
+      x[row] = x[row] - mult * x[col];
     }
   else if (std::abs(e) > std::abs(d))
     {
       get(row, col) = 0.0;
       get(col, col) = e;
-      double mult = d/e;
+      double mult = d / e;
       for (int i = col + 1; i < ncols(); i++)
         {
           double tx = get(col, i);
           double ty = get(row, i);
           get(col, i) = ty;
-          get(row, i) = tx - mult*ty;
+          get(row, i) = tx - mult * ty;
         }
       double tx = x[col];
       double ty = x[row];
       x[col] = ty;
-      x[row] = tx - mult*ty;
+      x[row] = tx - mult * ty;
     }
 }
 
 void
-SylvMatrix::eliminateRight(int row, int col, Vector &x)
+SylvMatrix::eliminateRight(int row, int col, Vector& x)
 {
   double d = get(row, row);
   double e = get(row, col);
@@ -149,32 +148,32 @@ SylvMatrix::eliminateRight(int row, int col, Vector &x)
   if (std::abs(d) > std::abs(e))
     {
       get(row, col) = 0.0;
-      double mult = e/d;
+      double mult = e / d;
       for (int i = 0; i < row; i++)
-        get(i, col) = get(i, col) - mult*get(i, row);
-      x[col] = x[col] - mult*x[row];
+        get(i, col) = get(i, col) - mult * get(i, row);
+      x[col] = x[col] - mult * x[row];
     }
   else if (std::abs(e) > std::abs(d))
     {
       get(row, col) = 0.0;
       get(row, row) = e;
-      double mult = d/e;
+      double mult = d / e;
       for (int i = 0; i < row; i++)
         {
           double tx = get(i, row);
           double ty = get(i, col);
           get(i, row) = ty;
-          get(i, col) = tx - mult*ty;
+          get(i, col) = tx - mult * ty;
         }
       double tx = x[row];
       double ty = x[col];
       x[row] = ty;
-      x[col] = tx - mult*ty;
+      x[col] = tx - mult * ty;
     }
 }
 
 void
-SqSylvMatrix::multVecKron(KronVector &x, const ConstKronVector &d) const
+SqSylvMatrix::multVecKron(KronVector& x, const ConstKronVector& d) const
 {
   x.zeros();
   if (d.getDepth() == 0)
@@ -201,7 +200,7 @@ SqSylvMatrix::multVecKron(KronVector &x, const ConstKronVector &d) const
 }
 
 void
-SqSylvMatrix::multVecKronTrans(KronVector &x, const ConstKronVector &d) const
+SqSylvMatrix::multVecKronTrans(KronVector& x, const ConstKronVector& d) const
 {
   x.zeros();
   if (d.getDepth() == 0)
@@ -228,8 +227,8 @@ SqSylvMatrix::multVecKronTrans(KronVector &x, const ConstKronVector &d) const
 }
 
 void
-SqSylvMatrix::multInvLeft2(GeneralMatrix &a, GeneralMatrix &b,
-                           double &rcond1, double &rcondinf) const
+SqSylvMatrix::multInvLeft2(GeneralMatrix& a, GeneralMatrix& b, double& rcond1,
+                           double& rcondinf) const
 {
   if (rows != a.nrows() || rows != b.nrows())
     throw SYLV_MES_EXCEPTION("Wrong dimensions for multInvLeft2.");
@@ -242,24 +241,20 @@ SqSylvMatrix::multInvLeft2(GeneralMatrix &a, GeneralMatrix &b,
   dgetrf(&rows2, &rows2, inv.base(), &lda, ipiv.get(), &info);
   // solve a
   lapack_int acols = a.ncols();
-  double *abase = a.base();
-  dgetrs("N", &rows2, &acols, inv.base(), &lda, ipiv.get(),
-         abase, &rows2, &info);
+  double* abase = a.base();
+  dgetrs("N", &rows2, &acols, inv.base(), &lda, ipiv.get(), abase, &rows2, &info);
   // solve b
   lapack_int bcols = b.ncols();
-  double *bbase = b.base();
-  dgetrs("N", &rows2, &bcols, inv.base(), &lda, ipiv.get(),
-         bbase, &rows2, &info);
+  double* bbase = b.base();
+  dgetrs("N", &rows2, &bcols, inv.base(), &lda, ipiv.get(), bbase, &rows2, &info);
 
   // condition numbers
-  auto work = std::make_unique<double[]>(4*rows);
+  auto work = std::make_unique<double[]>(4 * rows);
   auto iwork = std::make_unique<lapack_int[]>(rows);
   double norm1 = getNorm1();
-  dgecon("1", &rows2, inv.base(), &lda, &norm1, &rcond1,
-         work.get(), iwork.get(), &info);
+  dgecon("1", &rows2, inv.base(), &lda, &norm1, &rcond1, work.get(), iwork.get(), &info);
   double norminf = getNormInf();
-  dgecon("I", &rows2, inv.base(), &lda, &norminf, &rcondinf,
-         work.get(), iwork.get(), &info);
+  dgecon("I", &rows2, inv.base(), &lda, &norminf, &rcondinf, work.get(), iwork.get(), &info);
 }
 
 void
diff --git a/mex/sources/libkorder/sylv/SylvMatrix.hh b/mex/sources/libkorder/sylv/SylvMatrix.hh
index d1b0b947d4cac2ad44ab270d29233c8b81567520..c5ae4185b0cdc2907d83fd52ce027d78ab8f90cb 100644
--- a/mex/sources/libkorder/sylv/SylvMatrix.hh
+++ b/mex/sources/libkorder/sylv/SylvMatrix.hh
@@ -31,49 +31,46 @@ class SqSylvMatrix;
 class SylvMatrix : public GeneralMatrix
 {
 public:
-  SylvMatrix(int m, int n)
-    : GeneralMatrix(m, n)
+  SylvMatrix(int m, int n) : GeneralMatrix(m, n)
   {
   }
-  SylvMatrix(Vector d, int m, int n)
-    : GeneralMatrix(std::move(d), m, n)
+  SylvMatrix(Vector d, int m, int n) : GeneralMatrix(std::move(d), m, n)
   {
   }
-  SylvMatrix(const GeneralMatrix &m)
-    : GeneralMatrix(m)
+  SylvMatrix(const GeneralMatrix& m) : GeneralMatrix(m)
   {
   }
-  SylvMatrix(const GeneralMatrix &m, int i, int j, int nrows, int ncols)
-    : GeneralMatrix(m, i, j, nrows, ncols)
+  SylvMatrix(const GeneralMatrix& m, int i, int j, int nrows, int ncols) :
+      GeneralMatrix(m, i, j, nrows, ncols)
   {
   }
-  SylvMatrix(GeneralMatrix &m, int i, int j, int nrows, int ncols)
-    : GeneralMatrix(m, i, j, nrows, ncols)
+  SylvMatrix(GeneralMatrix& m, int i, int j, int nrows, int ncols) :
+      GeneralMatrix(m, i, j, nrows, ncols)
   {
   }
-  SylvMatrix(const SylvMatrix &m) = default;
-  SylvMatrix(SylvMatrix &&m) = default;
-  SylvMatrix &operator=(const SylvMatrix &m) = default;
-  SylvMatrix &operator=(SylvMatrix &&m) = default;
+  SylvMatrix(const SylvMatrix& m) = default;
+  SylvMatrix(SylvMatrix&& m) = default;
+  SylvMatrix& operator=(const SylvMatrix& m) = default;
+  SylvMatrix& operator=(SylvMatrix&& m) = default;
 
   /*        ⎛I 0⎞
      this = ⎝0 m⎠·this */
-  void multLeftI(const SqSylvMatrix &m);
+  void multLeftI(const SqSylvMatrix& m);
   /*        ⎛I  0⎞
      this = ⎝0 mᵀ⎠·this */
-  void multLeftITrans(const SqSylvMatrix &m);
+  void multLeftITrans(const SqSylvMatrix& m);
   // this = (0 a)·b, so that (0 a) is square
-  void multLeft(int zero_cols, const GeneralMatrix &a, const GeneralMatrix &b);
+  void multLeft(int zero_cols, const GeneralMatrix& a, const GeneralMatrix& b);
   // this = this·(m⊗m⊗…⊗m)
-  void multRightKron(const SqSylvMatrix &m, int order);
+  void multRightKron(const SqSylvMatrix& m, int order);
   // this = this·(mᵀ⊗mᵀ⊗…⊗mᵀ)
-  void multRightKronTrans(const SqSylvMatrix &m, int order);
+  void multRightKronTrans(const SqSylvMatrix& m, int order);
   /* this = P·this, x = P·x, where P is gauss transformation setting
      a given element to zero */
-  void eliminateLeft(int row, int col, Vector &x);
+  void eliminateLeft(int row, int col, Vector& x);
   /* this = this·P, x = Pᵀ·x, where P is gauss transformation setting
      a given element to zero */
-  void eliminateRight(int row, int col, Vector &x);
+  void eliminateRight(int row, int col, Vector& x);
 };
 
 class SqSylvMatrix : public SylvMatrix
@@ -85,28 +82,25 @@ public:
   SqSylvMatrix(Vector d, int m) : SylvMatrix(std::move(d), m, m)
   {
   }
-  SqSylvMatrix(const SylvMatrix &m) : SylvMatrix(m)
+  SqSylvMatrix(const SylvMatrix& m) : SylvMatrix(m)
   {
   }
-  SqSylvMatrix(const SqSylvMatrix &m) = default;
-  SqSylvMatrix(SqSylvMatrix &&m) = default;
-  SqSylvMatrix(const GeneralMatrix &m, int i, int j, int nrows)
-    : SylvMatrix(m, i, j, nrows, nrows)
+  SqSylvMatrix(const SqSylvMatrix& m) = default;
+  SqSylvMatrix(SqSylvMatrix&& m) = default;
+  SqSylvMatrix(const GeneralMatrix& m, int i, int j, int nrows) : SylvMatrix(m, i, j, nrows, nrows)
   {
   }
-  SqSylvMatrix(GeneralMatrix &m, int i, int j, int nrows)
-    : SylvMatrix(m, i, j, nrows, nrows)
+  SqSylvMatrix(GeneralMatrix& m, int i, int j, int nrows) : SylvMatrix(m, i, j, nrows, nrows)
   {
   }
-  SqSylvMatrix &operator=(const SqSylvMatrix &m) = default;
-  SqSylvMatrix &operator=(SqSylvMatrix &&m) = default;
+  SqSylvMatrix& operator=(const SqSylvMatrix& m) = default;
+  SqSylvMatrix& operator=(SqSylvMatrix&& m) = default;
   // x = (this⊗this⊗…⊗this)·d
-  void multVecKron(KronVector &x, const ConstKronVector &d) const;
+  void multVecKron(KronVector& x, const ConstKronVector& d) const;
   // x = (thisᵀ⊗thisᵀ⊗…⊗thisᵀ)·d
-  void multVecKronTrans(KronVector &x, const ConstKronVector &d) const;
+  void multVecKronTrans(KronVector& x, const ConstKronVector& d) const;
   // a = this⁻¹·a, b=this⁻¹·b */
-  void multInvLeft2(GeneralMatrix &a, GeneralMatrix &b,
-                    double &rcond1, double &rcondinf) const;
+  void multInvLeft2(GeneralMatrix& a, GeneralMatrix& b, double& rcond1, double& rcondinf) const;
   // this = I
   void setUnit();
 };
diff --git a/mex/sources/libkorder/sylv/SylvParams.cc b/mex/sources/libkorder/sylv/SylvParams.cc
index 3a3ede605846061f924da561b476bc04afe54e97..b2cfdb2b458d89e27827a4e723c899149ef022d4 100644
--- a/mex/sources/libkorder/sylv/SylvParams.cc
+++ b/mex/sources/libkorder/sylv/SylvParams.cc
@@ -23,38 +23,38 @@
 #include <iostream>
 
 void
-SylvParams::print(const std::string &prefix) const
+SylvParams::print(const std::string& prefix) const
 {
   print(std::cout, prefix);
 }
 
 void
-SylvParams::print(std::ostream &fdesc, const std::string &prefix) const
+SylvParams::print(std::ostream& fdesc, const std::string& prefix) const
 {
-  method.print(fdesc, prefix,    "method             ");
-  rcondA1.print(fdesc, prefix,   "reci. cond1 A      ");
-  rcondAI.print(fdesc, prefix,   "reci. cond∞ A      ");
-  bs_norm.print(fdesc, prefix,   "log₁₀ diag norm    ");
-  f_err1.print(fdesc, prefix,    "abs. err 1 F diag  ");
-  f_errI.print(fdesc, prefix,    "abs. err ∞ F diag  ");
-  viv_err1.print(fdesc, prefix,  "abs. err 1 V·V⁻¹   ");
-  viv_errI.print(fdesc, prefix,  "abs. err ∞ V·V⁻¹   ");
-  ivv_err1.print(fdesc, prefix,  "abs. err 1 V⁻¹·V   ");
-  ivv_errI.print(fdesc, prefix,  "abs. err ∞ V⁻¹·V   ");
-  f_blocks.print(fdesc, prefix,  "num blocks in F    ");
+  method.print(fdesc, prefix, "method             ");
+  rcondA1.print(fdesc, prefix, "reci. cond1 A      ");
+  rcondAI.print(fdesc, prefix, "reci. cond∞ A      ");
+  bs_norm.print(fdesc, prefix, "log₁₀ diag norm    ");
+  f_err1.print(fdesc, prefix, "abs. err 1 F diag  ");
+  f_errI.print(fdesc, prefix, "abs. err ∞ F diag  ");
+  viv_err1.print(fdesc, prefix, "abs. err 1 V·V⁻¹   ");
+  viv_errI.print(fdesc, prefix, "abs. err ∞ V·V⁻¹   ");
+  ivv_err1.print(fdesc, prefix, "abs. err 1 V⁻¹·V   ");
+  ivv_errI.print(fdesc, prefix, "abs. err ∞ V⁻¹·V   ");
+  f_blocks.print(fdesc, prefix, "num blocks in F    ");
   f_largest.print(fdesc, prefix, "largest block in F ");
-  f_zeros.print(fdesc, prefix,   "num zeros in F     ");
+  f_zeros.print(fdesc, prefix, "num zeros in F     ");
   f_offdiag.print(fdesc, prefix, "num offdiag in F   ");
   if (*method == solve_method::iter)
     {
-      converged.print(fdesc, prefix,       "converged          ");
+      converged.print(fdesc, prefix, "converged          ");
       convergence_tol.print(fdesc, prefix, "convergence tol.   ");
-      iter_last_norm.print(fdesc, prefix,  "last norm          ");
-      max_num_iter.print(fdesc, prefix,    "max num iter       ");
-      num_iter.print(fdesc, prefix,        "num iter           ");
+      iter_last_norm.print(fdesc, prefix, "last norm          ");
+      max_num_iter.print(fdesc, prefix, "max num iter       ");
+      num_iter.print(fdesc, prefix, "num iter           ");
     }
   else
-    eig_min.print(fdesc, prefix,         "minimum eigenvalue ");
+    eig_min.print(fdesc, prefix, "minimum eigenvalue ");
 
   mat_err1.print(fdesc, prefix, "rel. matrix norm1  ");
   mat_errI.print(fdesc, prefix, "rel. matrix norm∞  ");
@@ -65,7 +65,7 @@ SylvParams::print(std::ostream &fdesc, const std::string &prefix) const
 }
 
 void
-SylvParams::setArrayNames(int &num, const char **names) const
+SylvParams::setArrayNames(int& num, const char** names) const
 {
   num = 0;
   if (method.getStatus() != status::undef)
@@ -123,25 +123,25 @@ SylvParams::setArrayNames(int &num, const char **names) const
 }
 
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-mxArray *
+mxArray*
 SylvParams::DoubleParamItem::createMatlabArray() const
 {
   return mxCreateDoubleScalar(value);
 }
 
-mxArray *
+mxArray*
 SylvParams::IntParamItem::createMatlabArray() const
 {
-  mxArray *res = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
+  mxArray* res = mxCreateNumericMatrix(1, 1, mxINT32_CLASS, mxREAL);
 # if MX_HAS_INTERLEAVED_COMPLEX
   *mxGetInt32s(res) = value;
 # else
-  *static_cast<int *>(mxGetData(res)) = value;
+  *static_cast<int*>(mxGetData(res)) = value;
 # endif
   return res;
 }
 
-mxArray *
+mxArray*
 SylvParams::BoolParamItem::createMatlabArray() const
 {
   if (value)
@@ -150,7 +150,7 @@ SylvParams::BoolParamItem::createMatlabArray() const
     return mxCreateString("false");
 }
 
-mxArray *
+mxArray*
 SylvParams::MethodParamItem::createMatlabArray() const
 {
   if (value == solve_method::iter)
@@ -159,14 +159,14 @@ SylvParams::MethodParamItem::createMatlabArray() const
     return mxCreateString("recursive");
 }
 
-mxArray *
+mxArray*
 SylvParams::createStructArray() const
 {
-  const char *names[50];
+  const char* names[50];
   int num;
   setArrayNames(num, names);
   const mwSize dims[] = {1, 1};
-  mxArray *const res = mxCreateStructArray(2, dims, num, names);
+  mxArray* const res = mxCreateStructArray(2, dims, num, names);
 
   int i = 0;
   if (method.getStatus() != status::undef)
diff --git a/mex/sources/libkorder/sylv/SylvParams.hh b/mex/sources/libkorder/sylv/SylvParams.hh
index 099ab453cf82989900d952df0ca20a9130f4b835..8289cfc7ff52ce4b92282f1b23b0a1673a090440 100644
--- a/mex/sources/libkorder/sylv/SylvParams.hh
+++ b/mex/sources/libkorder/sylv/SylvParams.hh
@@ -21,14 +21,19 @@
 #ifndef SYLV_PARAMS_H
 #define SYLV_PARAMS_H
 
-#include <string>
 #include <ostream>
+#include <string>
 
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
 # include <dynmex.h>
 #endif
 
-enum class status { def, changed, undef };
+enum class status
+{
+  def,
+  changed,
+  undef
+};
 
 template<class _Type>
 struct ParamItem
@@ -37,6 +42,7 @@ protected:
   using _Self = ParamItem<_Type>;
   status s;
   _Type value;
+
 public:
   ParamItem()
   {
@@ -47,10 +53,10 @@ public:
     value = val;
     s = status::def;
   }
-  ParamItem(const _Self &item) = default;
-  _Self &operator=(const _Self &item) = default;
-  _Self &
-  operator=(const _Type &val)
+  ParamItem(const _Self& item) = default;
+  _Self& operator=(const _Self& item) = default;
+  _Self&
+  operator=(const _Type& val)
   {
     value = val;
     s = status::changed;
@@ -67,7 +73,7 @@ public:
     return s;
   }
   void
-  print(std::ostream &out, const std::string &prefix, const std::string &str) const
+  print(std::ostream& out, const std::string& prefix, const std::string& str) const
   {
     if (s == status::undef)
       return;
@@ -81,7 +87,11 @@ public:
 class SylvParams
 {
 public:
-  enum class solve_method { iter, recurse };
+  enum class solve_method
+  {
+    iter,
+    recurse
+  };
 
 protected:
   class DoubleParamItem : public ParamItem<double>
@@ -93,14 +103,15 @@ protected:
     DoubleParamItem(double val) : ParamItem<double>(val)
     {
     }
-    DoubleParamItem(const DoubleParamItem &item) = default;
-    DoubleParamItem &
-    operator=(const double &val)
+    DoubleParamItem(const DoubleParamItem& item) = default;
+    DoubleParamItem&
+    operator=(const double& val)
     {
-      ParamItem<double>::operator=(val); return *this;
+      ParamItem<double>::operator=(val);
+      return *this;
     }
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-    mxArray *createMatlabArray() const;
+    mxArray* createMatlabArray() const;
 #endif
   };
 
@@ -113,14 +124,15 @@ protected:
     IntParamItem(int val) : ParamItem<int>(val)
     {
     }
-    IntParamItem(const IntParamItem &item) = default;
-    IntParamItem &
-    operator=(const int &val)
+    IntParamItem(const IntParamItem& item) = default;
+    IntParamItem&
+    operator=(const int& val)
     {
-      ParamItem<int>::operator=(val); return *this;
+      ParamItem<int>::operator=(val);
+      return *this;
     }
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-    mxArray *createMatlabArray() const;
+    mxArray* createMatlabArray() const;
 #endif
   };
 
@@ -133,14 +145,15 @@ protected:
     BoolParamItem(bool val) : ParamItem<bool>(val)
     {
     }
-    BoolParamItem(const BoolParamItem &item) = default;
-    BoolParamItem &
-    operator=(const bool &val)
+    BoolParamItem(const BoolParamItem& item) = default;
+    BoolParamItem&
+    operator=(const bool& val)
     {
-      ParamItem<bool>::operator=(val); return *this;
+      ParamItem<bool>::operator=(val);
+      return *this;
     }
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-    mxArray *createMatlabArray() const;
+    mxArray* createMatlabArray() const;
 #endif
   };
 
@@ -153,68 +166,69 @@ protected:
     MethodParamItem(solve_method val) : ParamItem<solve_method>(val)
     {
     }
-    MethodParamItem(const MethodParamItem &item) = default;
+    MethodParamItem(const MethodParamItem& item) = default;
     MethodParamItem
-    operator=(const solve_method &val)
+    operator=(const solve_method& val)
     {
-      ParamItem<solve_method>::operator=(val); return *this;
+      ParamItem<solve_method>::operator=(val);
+      return *this;
     }
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-    mxArray *createMatlabArray() const;
+    mxArray* createMatlabArray() const;
 #endif
   };
 
 public:
   // input parameters
-  MethodParamItem method; // method of solution: iter/recurse
+  MethodParamItem method;          // method of solution: iter/recurse
   DoubleParamItem convergence_tol; // norm for what we consider converged
-  IntParamItem max_num_iter; // max number of iterations
-  DoubleParamItem bs_norm; // Bavely Stewart log₁₀ of norm for diagonalization
-  BoolParamItem want_check; // true => allocate extra space for checks
+  IntParamItem max_num_iter;       // max number of iterations
+  DoubleParamItem bs_norm;         // Bavely Stewart log₁₀ of norm for diagonalization
+  BoolParamItem want_check;        // true => allocate extra space for checks
   // output parameters
-  BoolParamItem converged; // true if converged
+  BoolParamItem converged;        // true if converged
   DoubleParamItem iter_last_norm; // norm of the last iteration
-  IntParamItem num_iter; // number of iterations
-  DoubleParamItem f_err1; // norm 1 of diagonalization abs. error C−V·F·V⁻¹
-  DoubleParamItem f_errI; // norm ∞ of diagonalization abs. error C−V·F·V⁻¹
-  DoubleParamItem viv_err1; // norm 1 of error I−V·V⁻¹
-  DoubleParamItem viv_errI; // norm ∞ of error I−V·V⁻¹
-  DoubleParamItem ivv_err1; // norm 1 of error I−V⁻¹·V
-  DoubleParamItem ivv_errI; // norm ∞ of error I−V⁻¹·V
-  IntParamItem f_blocks; // number of diagonal blocks of F
-  IntParamItem f_largest; // size of largest diagonal block in F
-  IntParamItem f_zeros; // number of off diagonal zeros in F
-  IntParamItem f_offdiag; // number of all off diagonal elements in F
-  DoubleParamItem rcondA1; // reciprocal cond 1 number of A
-  DoubleParamItem rcondAI; // reciprocal cond ∞ number of A
-  DoubleParamItem eig_min; // minimum eigenvalue of the solved system
-  DoubleParamItem mat_err1; // rel. matrix 1 norm of A·X−B·X·⊗ⁱC−D
-  DoubleParamItem mat_errI; // rel. matrix ∞ norm of A·X−B·X·⊗ⁱC−D
-  DoubleParamItem mat_errF; // rel. matrix Frob. norm of A·X−B·X·⊗ⁱC−D
-  DoubleParamItem vec_err1; // rel. vector 1 norm of A·X−B·X·⊗ⁱC−D
-  DoubleParamItem vec_errI; // rel. vector ∞ norm of A·X−B·X·⊗ⁱC−D
-  DoubleParamItem cpu_time; // time of the job in CPU seconds
+  IntParamItem num_iter;          // number of iterations
+  DoubleParamItem f_err1;         // norm 1 of diagonalization abs. error C−V·F·V⁻¹
+  DoubleParamItem f_errI;         // norm ∞ of diagonalization abs. error C−V·F·V⁻¹
+  DoubleParamItem viv_err1;       // norm 1 of error I−V·V⁻¹
+  DoubleParamItem viv_errI;       // norm ∞ of error I−V·V⁻¹
+  DoubleParamItem ivv_err1;       // norm 1 of error I−V⁻¹·V
+  DoubleParamItem ivv_errI;       // norm ∞ of error I−V⁻¹·V
+  IntParamItem f_blocks;          // number of diagonal blocks of F
+  IntParamItem f_largest;         // size of largest diagonal block in F
+  IntParamItem f_zeros;           // number of off diagonal zeros in F
+  IntParamItem f_offdiag;         // number of all off diagonal elements in F
+  DoubleParamItem rcondA1;        // reciprocal cond 1 number of A
+  DoubleParamItem rcondAI;        // reciprocal cond ∞ number of A
+  DoubleParamItem eig_min;        // minimum eigenvalue of the solved system
+  DoubleParamItem mat_err1;       // rel. matrix 1 norm of A·X−B·X·⊗ⁱC−D
+  DoubleParamItem mat_errI;       // rel. matrix ∞ norm of A·X−B·X·⊗ⁱC−D
+  DoubleParamItem mat_errF;       // rel. matrix Frob. norm of A·X−B·X·⊗ⁱC−D
+  DoubleParamItem vec_err1;       // rel. vector 1 norm of A·X−B·X·⊗ⁱC−D
+  DoubleParamItem vec_errI;       // rel. vector ∞ norm of A·X−B·X·⊗ⁱC−D
+  DoubleParamItem cpu_time;       // time of the job in CPU seconds
 
-  SylvParams(bool wc = false)
-    : method(solve_method::recurse), convergence_tol(1.e-30), max_num_iter(15),
-      bs_norm(1.3), want_check(wc)
+  SylvParams(bool wc = false) :
+      method(solve_method::recurse), convergence_tol(1.e-30), max_num_iter(15), bs_norm(1.3),
+      want_check(wc)
   {
   }
-  SylvParams(const SylvParams &p) = default;
-  SylvParams &operator=(const SylvParams &p) = default;
+  SylvParams(const SylvParams& p) = default;
+  SylvParams& operator=(const SylvParams& p) = default;
   ~SylvParams() = default;
-  void print(const std::string &prefix) const;
-  void print(std::ostream &fdesc, const std::string &prefix) const;
-  void setArrayNames(int &num, const char **names) const;
+  void print(const std::string& prefix) const;
+  void print(std::ostream& fdesc, const std::string& prefix) const;
+  void setArrayNames(int& num, const char** names) const;
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-  mxArray *createStructArray() const;
+  mxArray* createStructArray() const;
 #endif
 private:
-  void copy(const SylvParams &p);
+  void copy(const SylvParams& p);
 };
 
-inline std::ostream &
-operator<<(std::ostream &out, SylvParams::solve_method m)
+inline std::ostream&
+operator<<(std::ostream& out, SylvParams::solve_method m)
 {
   switch (m)
     {
diff --git a/mex/sources/libkorder/sylv/SylvesterSolver.hh b/mex/sources/libkorder/sylv/SylvesterSolver.hh
index a77f45cd4aa2daa15199d38e79906e186cb7b108..9543ffce6d78a15f8892a4a61a37524312d55ebe 100644
--- a/mex/sources/libkorder/sylv/SylvesterSolver.hh
+++ b/mex/sources/libkorder/sylv/SylvesterSolver.hh
@@ -24,9 +24,9 @@
 #include "KronVector.hh"
 #include "QuasiTriangular.hh"
 #include "QuasiTriangularZero.hh"
+#include "SchurDecomp.hh"
 #include "SimilarityDecomp.hh"
 #include "SylvParams.hh"
-#include "SchurDecomp.hh"
 
 #include <memory>
 
@@ -35,37 +35,35 @@ class SylvesterSolver
 protected:
   const std::unique_ptr<const QuasiTriangular> matrixK;
   const std::unique_ptr<const QuasiTriangular> matrixF;
+
 private:
   /* Return true when it is more efficient to use QuasiTriangular
      than QuasiTriangularZero */
   static bool
-  zeroPad(const SchurDecompZero &kdecomp)
+  zeroPad(const SchurDecompZero& kdecomp)
   {
-    return ((kdecomp.getZeroCols()*3 < kdecomp.getDim()*2)
-            || (kdecomp.getZeroCols() < 10));
+    return ((kdecomp.getZeroCols() * 3 < kdecomp.getDim() * 2) || (kdecomp.getZeroCols() < 10));
   }
+
 public:
-  SylvesterSolver(const QuasiTriangular &k, const QuasiTriangular &f)
-    : matrixK(std::make_unique<QuasiTriangular>(k)),
-      matrixF(std::make_unique<QuasiTriangular>(f))
+  SylvesterSolver(const QuasiTriangular& k, const QuasiTriangular& f) :
+      matrixK(std::make_unique<QuasiTriangular>(k)), matrixF(std::make_unique<QuasiTriangular>(f))
   {
   }
-  SylvesterSolver(const SchurDecompZero &kdecomp, const SchurDecomp &fdecomp)
-    : matrixK((zeroPad(kdecomp)) ?
-              std::make_unique<QuasiTriangular>(kdecomp) :
-              std::make_unique<QuasiTriangularZero>(kdecomp)),
+  SylvesterSolver(const SchurDecompZero& kdecomp, const SchurDecomp& fdecomp) :
+      matrixK((zeroPad(kdecomp)) ? std::make_unique<QuasiTriangular>(kdecomp)
+                                 : std::make_unique<QuasiTriangularZero>(kdecomp)),
       matrixF(std::make_unique<QuasiTriangular>(fdecomp))
   {
   }
-  SylvesterSolver(const SchurDecompZero &kdecomp, const SimilarityDecomp &fdecomp)
-    : matrixK((zeroPad(kdecomp)) ?
-              std::make_unique<QuasiTriangular>(kdecomp) :
-              std::make_unique<QuasiTriangularZero>(kdecomp)),
+  SylvesterSolver(const SchurDecompZero& kdecomp, const SimilarityDecomp& fdecomp) :
+      matrixK((zeroPad(kdecomp)) ? std::make_unique<QuasiTriangular>(kdecomp)
+                                 : std::make_unique<QuasiTriangularZero>(kdecomp)),
       matrixF(std::make_unique<BlockDiagonal>(fdecomp.getB()))
   {
   }
   virtual ~SylvesterSolver() = default;
-  virtual void solve(SylvParams &pars, KronVector &x) const = 0;
+  virtual void solve(SylvParams& pars, KronVector& x) const = 0;
 };
 
 #endif /* SYLVESTER_SOLVER_H */
diff --git a/mex/sources/libkorder/sylv/SymSchurDecomp.cc b/mex/sources/libkorder/sylv/SymSchurDecomp.cc
index 70e28e1e874dc76b7e79a98557994be5f8ebef7b..c7728aa2b540b6ff30c210ec48867ef02a80a1ff 100644
--- a/mex/sources/libkorder/sylv/SymSchurDecomp.cc
+++ b/mex/sources/libkorder/sylv/SymSchurDecomp.cc
@@ -27,8 +27,8 @@
 #include <cmath>
 #include <memory>
 
-SymSchurDecomp::SymSchurDecomp(const ConstGeneralMatrix &mata)
-  : lambda(mata.nrows()), q(mata.nrows())
+SymSchurDecomp::SymSchurDecomp(const ConstGeneralMatrix& mata) :
+    lambda(mata.nrows()), q(mata.nrows())
 {
   // check mata is square
   if (mata.nrows() != mata.ncols())
@@ -37,20 +37,20 @@ SymSchurDecomp::SymSchurDecomp(const ConstGeneralMatrix &mata)
   // prepare for dsyevr
   lapack_int n = mata.nrows();
   GeneralMatrix tmpa(mata);
-  double *a = tmpa.base();
+  double* a = tmpa.base();
   lapack_int lda = tmpa.getLD();
   double dum;
-  double *vl = &dum;
-  double *vu = &dum;
+  double* vl = &dum;
+  double* vu = &dum;
   lapack_int idum;
-  lapack_int *il = &idum;
-  lapack_int *iu = &idum;
+  lapack_int* il = &idum;
+  lapack_int* iu = &idum;
   double abstol = 0.0;
   lapack_int m = n;
-  double *w = lambda.base();
-  double *z = q.base();
+  double* w = lambda.base();
+  double* z = q.base();
   lapack_int ldz = q.getLD();
-  auto isuppz = std::make_unique<lapack_int[]>(2*std::max(1, static_cast<int>(m)));
+  auto isuppz = std::make_unique<lapack_int[]>(2 * std::max(1, static_cast<int>(m)));
   double tmpwork;
   lapack_int lwork = -1;
   lapack_int tmpiwork;
@@ -58,8 +58,8 @@ SymSchurDecomp::SymSchurDecomp(const ConstGeneralMatrix &mata)
   lapack_int info;
 
   // query for lwork and liwork
-  dsyevr("V", "A", "U", &n, a, &lda, vl, vu, il, iu, &abstol,
-         &m, w, z, &ldz, isuppz.get(), &tmpwork, &lwork, &tmpiwork, &liwork, &info);
+  dsyevr("V", "A", "U", &n, a, &lda, vl, vu, il, iu, &abstol, &m, w, z, &ldz, isuppz.get(),
+         &tmpwork, &lwork, &tmpiwork, &liwork, &info);
   lwork = static_cast<lapack_int>(tmpwork);
   liwork = tmpiwork;
   // allocate work arrays
@@ -67,8 +67,8 @@ SymSchurDecomp::SymSchurDecomp(const ConstGeneralMatrix &mata)
   auto iwork = std::make_unique<lapack_int[]>(liwork);
 
   // do the calculation
-  dsyevr("V", "A", "U", &n, a, &lda, vl, vu, il, iu, &abstol,
-         &m, w, z, &ldz, isuppz.get(), work.get(), &lwork, iwork.get(), &liwork, &info);
+  dsyevr("V", "A", "U", &n, a, &lda, vl, vu, il, iu, &abstol, &m, w, z, &ldz, isuppz.get(),
+         work.get(), &lwork, iwork.get(), &liwork, &info);
 
   if (info < 0)
     throw SYLV_MES_EXCEPTION("Internal error in SymSchurDecomp constructor");
@@ -77,19 +77,20 @@ SymSchurDecomp::SymSchurDecomp(const ConstGeneralMatrix &mata)
 }
 
 void
-SymSchurDecomp::getFactor(GeneralMatrix &f) const
+SymSchurDecomp::getFactor(GeneralMatrix& f) const
 {
   if (f.nrows() != q.nrows())
     throw SYLV_MES_EXCEPTION("Wrong dimension of factor matrix in SymSchurDecomp::getFactor");
   if (f.nrows() != f.ncols())
     throw SYLV_MES_EXCEPTION("Factor matrix is not square in SymSchurDecomp::getFactor");
   if (!isPositiveSemidefinite())
-    throw SYLV_MES_EXCEPTION("Symmetric decomposition not positive semidefinite in SymSchurDecomp::getFactor");
+    throw SYLV_MES_EXCEPTION(
+        "Symmetric decomposition not positive semidefinite in SymSchurDecomp::getFactor");
 
   f = q;
   for (int i = 0; i < f.ncols(); i++)
     {
-      Vector fi{f.getCol(i)};
+      Vector fi {f.getCol(i)};
       fi.mult(std::sqrt(lambda[i]));
     }
 }
diff --git a/mex/sources/libkorder/sylv/SymSchurDecomp.hh b/mex/sources/libkorder/sylv/SymSchurDecomp.hh
index c16fd1e93141fdb2f10af66eb07f051b658bd648..523b0601a175b3aa5fd424d4521a3167c887397d 100644
--- a/mex/sources/libkorder/sylv/SymSchurDecomp.hh
+++ b/mex/sources/libkorder/sylv/SymSchurDecomp.hh
@@ -28,25 +28,26 @@ class SymSchurDecomp
 protected:
   Vector lambda;
   SqSylvMatrix q;
+
 public:
   /* Computes the factorization A = Q·Λ·Qᵀ, where A is assummed to be
      symmetric and Λ real diagonal, hence a vector. */
-  SymSchurDecomp(const ConstGeneralMatrix &a);
-  SymSchurDecomp(const SymSchurDecomp &ssd) = default;
+  SymSchurDecomp(const ConstGeneralMatrix& a);
+  SymSchurDecomp(const SymSchurDecomp& ssd) = default;
   virtual ~SymSchurDecomp() = default;
-  const Vector &
+  const Vector&
   getLambda() const
   {
     return lambda;
   }
-  const SqSylvMatrix &
+  const SqSylvMatrix&
   getQ() const
   {
     return q;
   }
   /* Return factor F·Fᵀ = A, raises and exception if A is not
      positive semidefinite, F must be square. */
-  void getFactor(GeneralMatrix &f) const;
+  void getFactor(GeneralMatrix& f) const;
   // Returns true if A is positive semidefinite.
   bool isPositiveSemidefinite() const;
   /* Correct definitness. This sets all eigenvalues between minus
diff --git a/mex/sources/libkorder/sylv/TriangularSylvester.cc b/mex/sources/libkorder/sylv/TriangularSylvester.cc
index b690712efaa84cd66091af2127c39cc6317dd121..95aec463514b8913d6eb8c56313f36b22ab5d256 100644
--- a/mex/sources/libkorder/sylv/TriangularSylvester.cc
+++ b/mex/sources/libkorder/sylv/TriangularSylvester.cc
@@ -19,34 +19,29 @@
  */
 
 #include "TriangularSylvester.hh"
-#include "QuasiTriangularZero.hh"
-#include "KronUtils.hh"
 #include "BlockDiagonal.hh"
+#include "KronUtils.hh"
+#include "QuasiTriangularZero.hh"
 
-#include <iostream>
 #include <cmath>
+#include <iostream>
 
-TriangularSylvester::TriangularSylvester(const QuasiTriangular &k,
-                                         const QuasiTriangular &f)
-  : SylvesterSolver(k, f),
-    matrixKK{matrixK->square()},
-    matrixFF{matrixF->square()}
+TriangularSylvester::TriangularSylvester(const QuasiTriangular& k, const QuasiTriangular& f) :
+    SylvesterSolver(k, f), matrixKK {matrixK->square()}, matrixFF {matrixF->square()}
 {
 }
 
-TriangularSylvester::TriangularSylvester(const SchurDecompZero &kdecomp,
-                                         const SchurDecomp &fdecomp)
-  : SylvesterSolver(kdecomp, fdecomp),
-    matrixKK{matrixK->square()},
-    matrixFF{matrixF->square()}
+TriangularSylvester::TriangularSylvester(const SchurDecompZero& kdecomp,
+                                         const SchurDecomp& fdecomp) :
+    SylvesterSolver(kdecomp, fdecomp),
+    matrixKK {matrixK->square()}, matrixFF {matrixF->square()}
 {
 }
 
-TriangularSylvester::TriangularSylvester(const SchurDecompZero &kdecomp,
-                                         const SimilarityDecomp &fdecomp)
-  : SylvesterSolver(kdecomp, fdecomp),
-    matrixKK{matrixK->square()},
-    matrixFF{matrixF->square()}
+TriangularSylvester::TriangularSylvester(const SchurDecompZero& kdecomp,
+                                         const SimilarityDecomp& fdecomp) :
+    SylvesterSolver(kdecomp, fdecomp),
+    matrixKK {matrixK->square()}, matrixFF {matrixF->square()}
 {
 }
 
@@ -60,7 +55,7 @@ TriangularSylvester::print() const
 }
 
 void
-TriangularSylvester::solve(SylvParams &pars, KronVector &d) const
+TriangularSylvester::solve(SylvParams& pars, KronVector& d) const
 {
   double eig_min = 1e30;
   solvi(1., d, eig_min);
@@ -68,7 +63,7 @@ TriangularSylvester::solve(SylvParams &pars, KronVector &d) const
 }
 
 void
-TriangularSylvester::solvi(double r, KronVector &d, double &eig_min) const
+TriangularSylvester::solvi(double r, KronVector& d, double& eig_min) const
 {
   if (d.getDepth() == 0)
     {
@@ -77,9 +72,7 @@ TriangularSylvester::solvi(double r, KronVector &d, double &eig_min) const
     }
   else
     {
-      for (const_diag_iter di = matrixF->diag_begin();
-           di != matrixF->diag_end();
-           ++di)
+      for (const_diag_iter di = matrixF->diag_begin(); di != matrixF->diag_end(); ++di)
         if (di->isReal())
           solviRealAndEliminate(r, di, d, eig_min);
         else
@@ -88,20 +81,18 @@ TriangularSylvester::solvi(double r, KronVector &d, double &eig_min) const
 }
 
 void
-TriangularSylvester::solvii(double alpha, double beta1, double beta2,
-                            KronVector &d1, KronVector &d2,
-                            double &eig_min) const
+TriangularSylvester::solvii(double alpha, double beta1, double beta2, KronVector& d1,
+                            KronVector& d2, double& eig_min) const
 {
   KronVector d1tmp(d1);
   KronVector d2tmp(d2);
   linEval(alpha, beta1, beta2, d1, d2, d1tmp, d2tmp);
-  solviip(alpha, beta1*beta2, d1, eig_min);
-  solviip(alpha, beta1*beta2, d2, eig_min);
+  solviip(alpha, beta1 * beta2, d1, eig_min);
+  solviip(alpha, beta1 * beta2, d2, eig_min);
 }
 
 void
-TriangularSylvester::solviip(double alpha, double betas,
-                             KronVector &d, double &eig_min) const
+TriangularSylvester::solviip(double alpha, double betas, KronVector& d, double& eig_min) const
 {
   // quick exit to solvi if betas is small
   if (betas < diag_zero_sq)
@@ -113,8 +104,8 @@ TriangularSylvester::solviip(double alpha, double betas,
 
   if (d.getDepth() == 0)
     {
-      double aspbs = alpha*alpha+betas;
-      auto t = matrixK->linearlyCombine(2*alpha, aspbs, *matrixKK);
+      double aspbs = alpha * alpha + betas;
+      auto t = matrixK->linearlyCombine(2 * alpha, aspbs, *matrixKK);
       t->solvePre(d, eig_min);
     }
   else
@@ -130,18 +121,18 @@ TriangularSylvester::solviip(double alpha, double betas,
 }
 
 void
-TriangularSylvester::solviRealAndEliminate(double r, const_diag_iter di,
-                                           KronVector &d, double &eig_min) const
+TriangularSylvester::solviRealAndEliminate(double r, const_diag_iter di, KronVector& d,
+                                           double& eig_min) const
 {
   // di is real
   int jbar = di->getIndex();
   double f = *(di->getAlpha());
   KronVector dj(d, jbar);
   // solve system
-  if (std::abs(r*f) > diag_zero)
-    solvi(r*f, dj, eig_min);
+  if (std::abs(r * f) > diag_zero)
+    solvi(r * f, dj, eig_min);
   // calculate y
-  KronVector y(const_cast<const KronVector &>(dj));
+  KronVector y(const_cast<const KronVector&>(dj));
   KronUtils::multKron(*matrixF, *matrixK, y);
   y.mult(r);
   double divisor = 1.0;
@@ -149,20 +140,19 @@ TriangularSylvester::solviRealAndEliminate(double r, const_diag_iter di,
 }
 
 void
-TriangularSylvester::solviEliminateReal(const_diag_iter di, KronVector &d,
-                                        const KronVector &y, double divisor) const
+TriangularSylvester::solviEliminateReal(const_diag_iter di, KronVector& d, const KronVector& y,
+                                        double divisor) const
 {
-  for (const_row_iter ri = matrixF->row_begin(*di);
-       ri != matrixF->row_end(*di); ++ri)
+  for (const_row_iter ri = matrixF->row_begin(*di); ri != matrixF->row_end(*di); ++ri)
     {
       KronVector dk(d, ri.getCol());
-      dk.add(-(*ri)/divisor, y);
+      dk.add(-(*ri) / divisor, y);
     }
 }
 
 void
-TriangularSylvester::solviComplexAndEliminate(double r, const_diag_iter di,
-                                              KronVector &d, double &eig_min) const
+TriangularSylvester::solviComplexAndEliminate(double r, const_diag_iter di, KronVector& d,
+                                              double& eig_min) const
 {
   // di is complex
   int jbar = di->getIndex();
@@ -172,10 +162,10 @@ TriangularSylvester::solviComplexAndEliminate(double r, const_diag_iter di,
   double beta2 = -di->getBeta1();
   double aspbs = di->getDeterminant();
   KronVector dj(d, jbar);
-  KronVector djj(d, jbar+1);
+  KronVector djj(d, jbar + 1);
   // solve
-  if (r*r*aspbs > diag_zero_sq)
-    solvii(r*alpha, r*beta1, r*beta2, dj, djj, eig_min);
+  if (r * r * aspbs > diag_zero_sq)
+    solvii(r * alpha, r * beta1, r * beta2, dj, djj, eig_min);
   KronVector y1(dj);
   KronVector y2(djj);
   KronUtils::multKron(*matrixF, *matrixK, y1);
@@ -187,38 +177,36 @@ TriangularSylvester::solviComplexAndEliminate(double r, const_diag_iter di,
 }
 
 void
-TriangularSylvester::solviEliminateComplex(const_diag_iter di, KronVector &d,
-                                           const KronVector &y1, const KronVector &y2,
-                                           double divisor) const
+TriangularSylvester::solviEliminateComplex(const_diag_iter di, KronVector& d, const KronVector& y1,
+                                           const KronVector& y2, double divisor) const
 {
-  for (const_row_iter ri = matrixF->row_begin(*di);
-       ri != matrixF->row_end(*di); ++ri)
+  for (const_row_iter ri = matrixF->row_begin(*di); ri != matrixF->row_end(*di); ++ri)
     {
       KronVector dk(d, ri.getCol());
-      dk.add(-ri.a()/divisor, y1);
-      dk.add(-ri.b()/divisor, y2);
+      dk.add(-ri.a() / divisor, y1);
+      dk.add(-ri.b() / divisor, y2);
     }
 }
 
 void
-TriangularSylvester::solviipRealAndEliminate(double alpha, double betas,
-                                             const_diag_iter di, const_diag_iter dsi,
-                                             KronVector &d, double &eig_min) const
+TriangularSylvester::solviipRealAndEliminate(double alpha, double betas, const_diag_iter di,
+                                             const_diag_iter dsi, KronVector& d,
+                                             double& eig_min) const
 {
   // di, and dsi are real
   int jbar = di->getIndex();
-  double aspbs = alpha*alpha+betas;
+  double aspbs = alpha * alpha + betas;
   // pick data
   double f = *(di->getAlpha());
-  double fs = f*f;
+  double fs = f * f;
   KronVector dj(d, jbar);
   // solve
-  if (fs*aspbs > diag_zero_sq)
-    solviip(f*alpha, fs*betas, dj, eig_min);
-  KronVector y1(const_cast<const KronVector &>(dj));
-  KronVector y2(const_cast<const KronVector &>(dj));
+  if (fs * aspbs > diag_zero_sq)
+    solviip(f * alpha, fs * betas, dj, eig_min);
+  KronVector y1(const_cast<const KronVector&>(dj));
+  KronVector y2(const_cast<const KronVector&>(dj));
   KronUtils::multKron(*matrixF, *matrixK, y1);
-  y1.mult(2*alpha);
+  y1.mult(2 * alpha);
   KronUtils::multKron(*matrixFF, *matrixKK, y2);
   y2.mult(aspbs);
   double divisor = 1.0;
@@ -227,9 +215,8 @@ TriangularSylvester::solviipRealAndEliminate(double alpha, double betas,
 }
 
 void
-TriangularSylvester::solviipEliminateReal(const_diag_iter di, const_diag_iter dsi,
-                                          KronVector &d,
-                                          const KronVector &y1, const KronVector &y2,
+TriangularSylvester::solviipEliminateReal(const_diag_iter di, const_diag_iter dsi, KronVector& d,
+                                          const KronVector& y1, const KronVector& y2,
                                           double divisor, double divisor2) const
 {
   const_row_iter ri = matrixF->row_begin(*di);
@@ -237,43 +224,43 @@ TriangularSylvester::solviipEliminateReal(const_diag_iter di, const_diag_iter ds
   for (; ri != matrixF->row_end(*di); ++ri, ++rsi)
     {
       KronVector dk(d, ri.getCol());
-      dk.add(-(*ri)/divisor, y1);
-      dk.add(-(*rsi)/divisor2, y2);
+      dk.add(-(*ri) / divisor, y1);
+      dk.add(-(*rsi) / divisor2, y2);
     }
 }
 
 void
-TriangularSylvester::solviipComplexAndEliminate(double alpha, double betas,
-                                                const_diag_iter di, const_diag_iter dsi,
-                                                KronVector &d, double &eig_min) const
+TriangularSylvester::solviipComplexAndEliminate(double alpha, double betas, const_diag_iter di,
+                                                const_diag_iter dsi, KronVector& d,
+                                                double& eig_min) const
 {
   // di, and dsi are complex
   int jbar = di->getIndex();
-  double aspbs = alpha*alpha+betas;
+  double aspbs = alpha * alpha + betas;
   // pick data
   double gamma = *(di->getAlpha());
   double delta1 = di->getBeta2(); // swap because of transpose
   double delta2 = -di->getBeta1();
   double gspds = di->getDeterminant();
   KronVector dj(d, jbar);
-  KronVector djj(d, jbar+1);
-  if (gspds*aspbs > diag_zero_sq)
+  KronVector djj(d, jbar + 1);
+  if (gspds * aspbs > diag_zero_sq)
     solviipComplex(alpha, betas, gamma, delta1, delta2, dj, djj, eig_min);
   // here dj, djj is solution, set y1, y2, y11, y22
   // y1
-  KronVector y1(const_cast<const KronVector &>(dj));
+  KronVector y1(const_cast<const KronVector&>(dj));
   KronUtils::multKron(*matrixF, *matrixK, y1);
-  y1.mult(2*alpha);
+  y1.mult(2 * alpha);
   // y11
-  KronVector y11(const_cast<const KronVector &>(djj));
+  KronVector y11(const_cast<const KronVector&>(djj));
   KronUtils::multKron(*matrixF, *matrixK, y11);
-  y11.mult(2*alpha);
+  y11.mult(2 * alpha);
   // y2
-  KronVector y2(const_cast<const KronVector &>(dj));
+  KronVector y2(const_cast<const KronVector&>(dj));
   KronUtils::multKron(*matrixFF, *matrixKK, y2);
   y2.mult(aspbs);
   // y22
-  KronVector y22(const_cast<const KronVector &>(djj));
+  KronVector y22(const_cast<const KronVector&>(djj));
   KronUtils::multKron(*matrixFF, *matrixKK, y22);
   y22.mult(aspbs);
 
@@ -282,32 +269,29 @@ TriangularSylvester::solviipComplexAndEliminate(double alpha, double betas,
 }
 
 void
-TriangularSylvester::solviipComplex(double alpha, double betas, double gamma,
-                                    double delta1, double delta2,
-                                    KronVector &d1, KronVector &d2,
-                                    double &eig_min) const
+TriangularSylvester::solviipComplex(double alpha, double betas, double gamma, double delta1,
+                                    double delta2, KronVector& d1, KronVector& d2,
+                                    double& eig_min) const
 {
   KronVector d1tmp(d1);
   KronVector d2tmp(d2);
-  quaEval(alpha, betas, gamma, delta1, delta2,
-          d1, d2, d1tmp, d2tmp);
-  double delta = std::sqrt(delta1*delta2);
+  quaEval(alpha, betas, gamma, delta1, delta2, d1, d2, d1tmp, d2tmp);
+  double delta = std::sqrt(delta1 * delta2);
   double beta = std::sqrt(betas);
-  double a1 = alpha*gamma - beta*delta;
-  double b1 = alpha*delta + gamma*beta;
-  double a2 = alpha*gamma + beta*delta;
-  double b2 = alpha*delta - gamma*beta;
-  solviip(a2, b2*b2, d1, eig_min);
-  solviip(a1, b1*b1, d1, eig_min);
-  solviip(a2, b2*b2, d2, eig_min);
-  solviip(a1, b1*b1, d2, eig_min);
+  double a1 = alpha * gamma - beta * delta;
+  double b1 = alpha * delta + gamma * beta;
+  double a2 = alpha * gamma + beta * delta;
+  double b2 = alpha * delta - gamma * beta;
+  solviip(a2, b2 * b2, d1, eig_min);
+  solviip(a1, b1 * b1, d1, eig_min);
+  solviip(a2, b2 * b2, d2, eig_min);
+  solviip(a1, b1 * b1, d2, eig_min);
 }
 
 void
-TriangularSylvester::solviipEliminateComplex(const_diag_iter di, const_diag_iter dsi,
-                                             KronVector &d,
-                                             const KronVector &y1, const KronVector &y11,
-                                             const KronVector &y2, const KronVector &y22,
+TriangularSylvester::solviipEliminateComplex(const_diag_iter di, const_diag_iter dsi, KronVector& d,
+                                             const KronVector& y1, const KronVector& y11,
+                                             const KronVector& y2, const KronVector& y22,
                                              double divisor) const
 {
   const_row_iter ri = matrixF->row_begin(*di);
@@ -315,17 +299,17 @@ TriangularSylvester::solviipEliminateComplex(const_diag_iter di, const_diag_iter
   for (; ri != matrixF->row_end(*di); ++ri, ++rsi)
     {
       KronVector dk(d, ri.getCol());
-      dk.add(-ri.a()/divisor, y1);
-      dk.add(-ri.b()/divisor, y11);
-      dk.add(-rsi.a()/divisor, y2);
-      dk.add(-rsi.b()/divisor, y22);
+      dk.add(-ri.a() / divisor, y1);
+      dk.add(-ri.b() / divisor, y11);
+      dk.add(-rsi.a() / divisor, y2);
+      dk.add(-rsi.b() / divisor, y22);
     }
 }
 
 void
-TriangularSylvester::linEval(double alpha, double beta1, double beta2,
-                             KronVector &x1, KronVector &x2,
-                             const ConstKronVector &d1, const ConstKronVector &d2) const
+TriangularSylvester::linEval(double alpha, double beta1, double beta2, KronVector& x1,
+                             KronVector& x2, const ConstKronVector& d1,
+                             const ConstKronVector& d2) const
 {
   KronVector d1tmp(d1); // make copy
   KronVector d2tmp(d2); // make copy
@@ -337,10 +321,9 @@ TriangularSylvester::linEval(double alpha, double beta1, double beta2,
 }
 
 void
-TriangularSylvester::quaEval(double alpha, double betas,
-                             double gamma, double delta1, double delta2,
-                             KronVector &x1, KronVector &x2,
-                             const ConstKronVector &d1, const ConstKronVector &d2) const
+TriangularSylvester::quaEval(double alpha, double betas, double gamma, double delta1, double delta2,
+                             KronVector& x1, KronVector& x2, const ConstKronVector& d1,
+                             const ConstKronVector& d2) const
 {
   KronVector d1tmp(d1); // make copy
   KronVector d2tmp(d2); // make copy
@@ -348,37 +331,36 @@ TriangularSylvester::quaEval(double alpha, double betas,
   KronUtils::multKron(*matrixF, *matrixK, d2tmp);
   x1 = d1;
   x2 = d2;
-  Vector::mult2a(2*alpha*gamma, 2*alpha*delta1, -2*alpha*delta2,
-                 x1, x2, d1tmp, d2tmp);
+  Vector::mult2a(2 * alpha * gamma, 2 * alpha * delta1, -2 * alpha * delta2, x1, x2, d1tmp, d2tmp);
   d1tmp = d1; // restore to d1
   d2tmp = d2; // restore to d2
   KronUtils::multKron(*matrixFF, *matrixKK, d1tmp);
   KronUtils::multKron(*matrixFF, *matrixKK, d2tmp);
-  double aspbs = alpha*alpha + betas;
-  double gspds = gamma*gamma - delta1*delta2;
-  Vector::mult2a(aspbs*gspds, 2*aspbs*gamma*delta1, -2*aspbs*gamma*delta2,
-                 x1, x2, d1tmp, d2tmp);
+  double aspbs = alpha * alpha + betas;
+  double gspds = gamma * gamma - delta1 * delta2;
+  Vector::mult2a(aspbs * gspds, 2 * aspbs * gamma * delta1, -2 * aspbs * gamma * delta2, x1, x2,
+                 d1tmp, d2tmp);
 }
 
 double
 TriangularSylvester::getEigSep(int depth) const
 {
   int f_size = matrixF->getDiagonal().getSize();
-  Vector feig(2*f_size);
+  Vector feig(2 * f_size);
   matrixF->getDiagonal().getEigenValues(feig);
   int k_size = matrixK->getDiagonal().getSize();
-  Vector keig(2*k_size);
+  Vector keig(2 * k_size);
   matrixK->getDiagonal().getEigenValues(keig);
 
-  KronVector eig(f_size, 2*k_size, depth);
+  KronVector eig(f_size, 2 * k_size, depth);
   multEigVector(eig, feig, keig);
 
   double min = 1.0e20;
-  for (int i = 0; i < eig.length()/2; i++)
+  for (int i = 0; i < eig.length() / 2; i++)
     {
-      double alpha = eig[2*i];
-      double beta = eig[2*i+1];
-      double ss = (alpha+1)*(alpha+1)+beta*beta;
+      double alpha = eig[2 * i];
+      double beta = eig[2 * i + 1];
+      double ss = (alpha + 1) * (alpha + 1) + beta * beta;
       min = std::min(min, ss);
     }
 
@@ -386,8 +368,7 @@ TriangularSylvester::getEigSep(int depth) const
 }
 
 void
-TriangularSylvester::multEigVector(KronVector &eig, const Vector &feig,
-                                   const Vector &keig)
+TriangularSylvester::multEigVector(KronVector& eig, const Vector& feig, const Vector& keig)
 {
   int depth = eig.getDepth();
   int m = eig.getM();
@@ -397,13 +378,13 @@ TriangularSylvester::multEigVector(KronVector &eig, const Vector &feig,
     eig = keig;
   else
     {
-      KronVector aux(m, n, depth-1);
+      KronVector aux(m, n, depth - 1);
       multEigVector(aux, feig, keig);
       for (int i = 0; i < m; i++)
         {
           KronVector eigi(eig, i);
           eigi.zeros();
-          eigi.addComplex({ feig[2*i], feig[2*i+1] }, aux);
+          eigi.addComplex({feig[2 * i], feig[2 * i + 1]}, aux);
         }
     }
 }
diff --git a/mex/sources/libkorder/sylv/TriangularSylvester.hh b/mex/sources/libkorder/sylv/TriangularSylvester.hh
index 2b9121229fcc3f72506f5c988581f3357ec8c94f..ceff2ab409f86f7090a5d50b5ca85fd586982f11 100644
--- a/mex/sources/libkorder/sylv/TriangularSylvester.hh
+++ b/mex/sources/libkorder/sylv/TriangularSylvester.hh
@@ -21,11 +21,11 @@
 #ifndef TRIANGULAR_SYLVESTER_H
 #define TRIANGULAR_SYLVESTER_H
 
-#include "SylvesterSolver.hh"
 #include "KronVector.hh"
 #include "QuasiTriangular.hh"
 #include "QuasiTriangularZero.hh"
 #include "SimilarityDecomp.hh"
+#include "SylvesterSolver.hh"
 
 #include <memory>
 
@@ -33,36 +33,32 @@ class TriangularSylvester : public SylvesterSolver
 {
   const std::unique_ptr<const QuasiTriangular> matrixKK;
   const std::unique_ptr<const QuasiTriangular> matrixFF;
+
 public:
-  TriangularSylvester(const QuasiTriangular &k, const QuasiTriangular &f);
-  TriangularSylvester(const SchurDecompZero &kdecomp, const SchurDecomp &fdecomp);
-  TriangularSylvester(const SchurDecompZero &kdecomp, const SimilarityDecomp &fdecomp);
+  TriangularSylvester(const QuasiTriangular& k, const QuasiTriangular& f);
+  TriangularSylvester(const SchurDecompZero& kdecomp, const SchurDecomp& fdecomp);
+  TriangularSylvester(const SchurDecompZero& kdecomp, const SimilarityDecomp& fdecomp);
 
   ~TriangularSylvester() override = default;
   void print() const;
-  void solve(SylvParams &pars, KronVector &d) const override;
+  void solve(SylvParams& pars, KronVector& d) const override;
 
-  void solvi(double r, KronVector &d, double &eig_min) const;
-  void solvii(double alpha, double beta1, double beta2,
-              KronVector &d1, KronVector &d2,
-              double &eig_min) const;
-  void solviip(double alpha, double betas,
-               KronVector &d, double &eig_min) const;
+  void solvi(double r, KronVector& d, double& eig_min) const;
+  void solvii(double alpha, double beta1, double beta2, KronVector& d1, KronVector& d2,
+              double& eig_min) const;
+  void solviip(double alpha, double betas, KronVector& d, double& eig_min) const;
   /* Computes:
      ⎛x₁⎞ ⎛d₁⎞ ⎛ α −β₁⎞           ⎛d₁⎞
      ⎢  ⎥=⎢  ⎥+⎢      ⎥⊗Fᵀ⊗Fᵀ⊗…⊗K·⎢  ⎥
      ⎝x₂⎠ ⎝d₂⎠ ⎝−β₂ α ⎠           ⎝d₂⎠
   */
-  void linEval(double alpha, double beta1, double beta2,
-               KronVector &x1, KronVector &x2,
-               const ConstKronVector &d1, const ConstKronVector &d2) const;
+  void linEval(double alpha, double beta1, double beta2, KronVector& x1, KronVector& x2,
+               const ConstKronVector& d1, const ConstKronVector& d2) const;
   void
-  linEval(double alpha, double beta1, double beta2,
-          KronVector &x1, KronVector &x2,
-          const KronVector &d1, const KronVector &d2) const
+  linEval(double alpha, double beta1, double beta2, KronVector& x1, KronVector& x2,
+          const KronVector& d1, const KronVector& d2) const
   {
-    linEval(alpha, beta1, beta2, x1, x2,
-            ConstKronVector(d1), ConstKronVector(d2));
+    linEval(alpha, beta1, beta2, x1, x2, ConstKronVector(d1), ConstKronVector(d2));
   }
 
   /* Computes:
@@ -70,64 +66,51 @@ public:
      ⎢  ⎥=⎢  ⎥+2α⎢     ⎥⊗Fᵀ⊗Fᵀ⊗…⊗K·⎢  ⎥+(α²+β)⎢     ⎥ ⊗Fᵀ²⊗Fᵀ²⊗…⊗K²·⎢  ⎥
      ⎝x₂⎠ ⎝d₂⎠   ⎝δ₂ γ ⎠           ⎝d₂⎠       ⎝δ₂ γ ⎠               ⎝d₂⎠
   */
-  void quaEval(double alpha, double betas,
-               double gamma, double delta1, double delta2,
-               KronVector &x1, KronVector &x2,
-               const ConstKronVector &d1, const ConstKronVector &d2) const;
+  void quaEval(double alpha, double betas, double gamma, double delta1, double delta2,
+               KronVector& x1, KronVector& x2, const ConstKronVector& d1,
+               const ConstKronVector& d2) const;
   void
-  quaEval(double alpha, double betas,
-          double gamma, double delta1, double delta2,
-          KronVector &x1, KronVector &x2,
-          const KronVector &d1, const KronVector &d2) const
+  quaEval(double alpha, double betas, double gamma, double delta1, double delta2, KronVector& x1,
+          KronVector& x2, const KronVector& d1, const KronVector& d2) const
   {
-    quaEval(alpha, betas, gamma, delta1, delta2, x1, x2,
-            ConstKronVector(d1), ConstKronVector(d2));
+    quaEval(alpha, betas, gamma, delta1, delta2, x1, x2, ConstKronVector(d1), ConstKronVector(d2));
   }
+
 private:
   /* Returns square of size of minimal eigenvalue of the system solved,
      now obsolete */
   double getEigSep(int depth) const;
   // Recursively calculates kronecker product of complex vectors (used in getEigSep)
-  static void multEigVector(KronVector &eig, const Vector &feig, const Vector &keig);
+  static void multEigVector(KronVector& eig, const Vector& feig, const Vector& keig);
 
   using const_diag_iter = QuasiTriangular::const_diag_iter;
   using const_row_iter = QuasiTriangular::const_row_iter;
 
   // Called from solvi
-  void solviRealAndEliminate(double r, const_diag_iter di,
-                             KronVector &d, double &eig_min) const;
-  void solviComplexAndEliminate(double r, const_diag_iter di,
-                                KronVector &d, double &eig_min) const;
+  void solviRealAndEliminate(double r, const_diag_iter di, KronVector& d, double& eig_min) const;
+  void solviComplexAndEliminate(double r, const_diag_iter di, KronVector& d, double& eig_min) const;
   // Called from solviip
-  void solviipRealAndEliminate(double alpha, double betas,
-                               const_diag_iter di, const_diag_iter dsi,
-                               KronVector &d, double &eig_min) const;
-  void solviipComplexAndEliminate(double alpha, double betas,
-                                  const_diag_iter di, const_diag_iter dsi,
-                                  KronVector &d, double &eig_min) const;
+  void solviipRealAndEliminate(double alpha, double betas, const_diag_iter di, const_diag_iter dsi,
+                               KronVector& d, double& eig_min) const;
+  void solviipComplexAndEliminate(double alpha, double betas, const_diag_iter di,
+                                  const_diag_iter dsi, KronVector& d, double& eig_min) const;
   // Eliminations
-  void solviEliminateReal(const_diag_iter di, KronVector &d,
-                          const KronVector &y, double divisor) const;
-  void solviEliminateComplex(const_diag_iter di, KronVector &d,
-                             const KronVector &y1, const KronVector &y2,
-                             double divisor) const;
-  void solviipEliminateReal(const_diag_iter di, const_diag_iter dsi,
-                            KronVector &d,
-                            const KronVector &y1, const KronVector &y2,
-                            double divisor, double divisor2) const;
-  void solviipEliminateComplex(const_diag_iter di, const_diag_iter dsi,
-                               KronVector &d,
-                               const KronVector &y1, const KronVector &y11,
-                               const KronVector &y2, const KronVector &y22,
-                               double divisor) const;
+  void solviEliminateReal(const_diag_iter di, KronVector& d, const KronVector& y,
+                          double divisor) const;
+  void solviEliminateComplex(const_diag_iter di, KronVector& d, const KronVector& y1,
+                             const KronVector& y2, double divisor) const;
+  void solviipEliminateReal(const_diag_iter di, const_diag_iter dsi, KronVector& d,
+                            const KronVector& y1, const KronVector& y2, double divisor,
+                            double divisor2) const;
+  void solviipEliminateComplex(const_diag_iter di, const_diag_iter dsi, KronVector& d,
+                               const KronVector& y1, const KronVector& y11, const KronVector& y2,
+                               const KronVector& y22, double divisor) const;
   // Lemma 2
-  void solviipComplex(double alpha, double betas, double gamma,
-                      double delta1, double delta2,
-                      KronVector &d1, KronVector &d2,
-                      double &eig_min) const;
+  void solviipComplex(double alpha, double betas, double gamma, double delta1, double delta2,
+                      KronVector& d1, KronVector& d2, double& eig_min) const;
   // Norms for what we consider zero on diagonal of F
   static constexpr double diag_zero = 1.e-15;
-  static constexpr double diag_zero_sq = diag_zero*diag_zero;
+  static constexpr double diag_zero_sq = diag_zero * diag_zero;
 };
 
 #endif /* TRIANGULAR_SYLVESTER_H */
diff --git a/mex/sources/libkorder/sylv/Vector.cc b/mex/sources/libkorder/sylv/Vector.cc
index c84453d717f2be6456b75794e8c6d2a966ef53b1..613f87a523faab35ca5886adea84d1f306e0a667 100644
--- a/mex/sources/libkorder/sylv/Vector.cc
+++ b/mex/sources/libkorder/sylv/Vector.cc
@@ -24,26 +24,24 @@
 
 #include <dynblas.h>
 
-#include <cmath>
 #include <algorithm>
-#include <limits>
-#include <iostream>
+#include <cmath>
 #include <iomanip>
+#include <iostream>
+#include <limits>
 
-Vector::Vector(const Vector &v)
-  : len(v.len), data{new double[len]}
+Vector::Vector(const Vector& v) : len(v.len), data {new double[len]}
 {
   copy(v.data, v.s);
 }
 
-Vector::Vector(const ConstVector &v)
-  : len(v.len), data{new double[len]}
+Vector::Vector(const ConstVector& v) : len(v.len), data {new double[len]}
 {
   copy(v.data, v.s);
 }
 
-Vector &
-Vector::operator=(const Vector &v)
+Vector&
+Vector::operator=(const Vector& v)
 {
   if (this == &v)
     return *this;
@@ -52,24 +50,24 @@ Vector::operator=(const Vector &v)
     throw SYLV_MES_EXCEPTION("Attempt to assign vectors with different lengths.");
 
   if (s == v.s
-      && ((data <= v.data && v.data < data+len*s)
-          || (v.data <= data && data < v.data+v.len*v.s))
-      && (data-v.data) % s == 0)
+      && ((data <= v.data && v.data < data + len * s)
+          || (v.data <= data && data < v.data + v.len * v.s))
+      && (data - v.data) % s == 0)
     throw SYLV_MES_EXCEPTION("Attempt to assign overlapping vectors.");
 
   copy(v.data, v.s);
   return *this;
 }
 
-Vector &
-Vector::operator=(const ConstVector &v)
+Vector&
+Vector::operator=(const ConstVector& v)
 {
   if (v.len != len)
     throw SYLV_MES_EXCEPTION("Attempt to assign vectors with different lengths.");
   if (s == v.s
-      && ((data <= v.data && v.data < data+len*s)
-          || (v.data <= data && data < v.data+v.len*v.s))
-      && (data-v.data) % s == 0)
+      && ((data <= v.data && v.data < data + len * s)
+          || (v.data <= data && data < v.data + v.len * v.s))
+      && (data - v.data) % s == 0)
     throw SYLV_MES_EXCEPTION("Attempt to assign overlapping vectors.");
 
   copy(v.data, v.s);
@@ -77,7 +75,7 @@ Vector::operator=(const ConstVector &v)
 }
 
 void
-Vector::copy(const double *d, int inc)
+Vector::copy(const double* d, int inc)
 {
   blas_int n = len;
   blas_int incy = s;
@@ -85,36 +83,33 @@ Vector::copy(const double *d, int inc)
   dcopy(&n, d, &inc2, data, &incy);
 }
 
-Vector::Vector(Vector &v, int off_arg, int l)
-  : len(l), s(v.s), data{v.data+off_arg*v.s}, destroy{false}
+Vector::Vector(Vector& v, int off_arg, int l) :
+    len(l), s(v.s), data {v.data + off_arg * v.s}, destroy {false}
 {
   if (off_arg < 0 || off_arg + len > v.len)
     throw SYLV_MES_EXCEPTION("Subvector not contained in supvector.");
 }
 
-Vector::Vector(const Vector &v, int off_arg, int l)
-  : len(l), data{new double[len]}
+Vector::Vector(const Vector& v, int off_arg, int l) : len(l), data {new double[len]}
 {
   if (off_arg < 0 || off_arg + len > v.len)
     throw SYLV_MES_EXCEPTION("Subvector not contained in supvector.");
-  copy(v.data+off_arg*v.s, v.s);
+  copy(v.data + off_arg * v.s, v.s);
 }
 
-Vector::Vector(Vector &v, int off_arg, int skip, int l)
-  : len(l), s(v.s*skip), data{v.data+off_arg*v.s}, destroy{false}
+Vector::Vector(Vector& v, int off_arg, int skip, int l) :
+    len(l), s(v.s * skip), data {v.data + off_arg * v.s}, destroy {false}
 {
 }
 
-Vector::Vector(const Vector &v, int off_arg, int skip, int l)
-  : len(l), data{new double[len]}
+Vector::Vector(const Vector& v, int off_arg, int skip, int l) : len(l), data {new double[len]}
 {
-  copy(v.data+off_arg*v.s, v.s*skip);
+  copy(v.data + off_arg * v.s, v.s * skip);
 }
 
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-Vector::Vector(mxArray *p)
-  : len{static_cast<int>(mxGetNumberOfElements(p))},
-    data{mxGetPr(p)}, destroy{false}
+Vector::Vector(mxArray* p) :
+    len {static_cast<int>(mxGetNumberOfElements(p))}, data {mxGetPr(p)}, destroy {false}
 {
   if (!mxIsDouble(p) || mxIsComplex(p) || mxIsSparse(p))
     throw SYLV_MES_EXCEPTION("This is not a dense array of real doubles.");
@@ -122,37 +117,37 @@ Vector::Vector(mxArray *p)
 #endif
 
 bool
-Vector::operator==(const Vector &y) const
+Vector::operator==(const Vector& y) const
 {
   return ConstVector(*this) == y;
 }
 
 bool
-Vector::operator!=(const Vector &y) const
+Vector::operator!=(const Vector& y) const
 {
   return ConstVector(*this) != y;
 }
 
 bool
-Vector::operator<(const Vector &y) const
+Vector::operator<(const Vector& y) const
 {
   return ConstVector(*this) < y;
 }
 
 bool
-Vector::operator<=(const Vector &y) const
+Vector::operator<=(const Vector& y) const
 {
   return ConstVector(*this) <= y;
 }
 
 bool
-Vector::operator>(const Vector &y) const
+Vector::operator>(const Vector& y) const
 {
   return ConstVector(*this) > y;
 }
 
 bool
-Vector::operator>=(const Vector &y) const
+Vector::operator>=(const Vector& y) const
 {
   return ConstVector(*this) >= y;
 }
@@ -184,19 +179,19 @@ Vector::infs()
 void
 Vector::rotatePair(double alpha, double beta1, double beta2, int i)
 {
-  double tmp = alpha*operator[](i) - beta1*operator[](i+1);
-  operator[](i+1) = alpha*operator[](i+1) - beta2*operator[](i);
+  double tmp = alpha * operator[](i) - beta1 * operator[](i + 1);
+  operator[](i + 1) = alpha * operator[](i + 1) - beta2 * operator[](i);
   operator[](i) = tmp;
 }
 
 void
-Vector::add(double r, const Vector &v)
+Vector::add(double r, const Vector& v)
 {
   add(r, ConstVector(v));
 }
 
 void
-Vector::add(double r, const ConstVector &v)
+Vector::add(double r, const ConstVector& v)
 {
   blas_int n = len;
   blas_int incx = v.s;
@@ -205,15 +200,15 @@ Vector::add(double r, const ConstVector &v)
 }
 
 void
-Vector::addComplex(const std::complex<double> &z, const Vector &v)
+Vector::addComplex(const std::complex<double>& z, const Vector& v)
 {
   addComplex(z, ConstVector(v));
 }
 
 void
-Vector::addComplex(const std::complex<double> &z, const ConstVector &v)
+Vector::addComplex(const std::complex<double>& z, const ConstVector& v)
 {
-  blas_int n = len/2;
+  blas_int n = len / 2;
   blas_int incx = v.s;
   blas_int incy = s;
   zaxpy(&n, reinterpret_cast<const double(&)[2]>(z), v.data, &incx, data, &incy);
@@ -228,9 +223,8 @@ Vector::mult(double r)
 }
 
 void
-Vector::mult2(double alpha, double beta1, double beta2,
-              Vector &x1, Vector &x2,
-              const Vector &b1, const Vector &b2)
+Vector::mult2(double alpha, double beta1, double beta2, Vector& x1, Vector& x2, const Vector& b1,
+              const Vector& b2)
 {
   x1.zeros();
   x2.zeros();
@@ -238,9 +232,8 @@ Vector::mult2(double alpha, double beta1, double beta2,
 }
 
 void
-Vector::mult2a(double alpha, double beta1, double beta2,
-               Vector &x1, Vector &x2,
-               const Vector &b1, const Vector &b2)
+Vector::mult2a(double alpha, double beta1, double beta2, Vector& x1, Vector& x2, const Vector& b1,
+               const Vector& b2)
 {
   x1.add(alpha, b1);
   x1.add(-beta1, b2);
@@ -270,7 +263,7 @@ Vector::getNorm1() const
 }
 
 double
-Vector::dot(const Vector &y) const
+Vector::dot(const Vector& y) const
 {
   return ConstVector(*this).dot(ConstVector(y));
 }
@@ -291,32 +284,29 @@ Vector::print() const
   std::cout.flags(ff);
 }
 
-ConstVector::ConstVector(const Vector &v)
-  : len{v.len}, s{v.s}, data{v.data}
+ConstVector::ConstVector(const Vector& v) : len {v.len}, s {v.s}, data {v.data}
 {
 }
 
-ConstVector::ConstVector(const ConstVector &v, int off_arg, int l)
-  : len{l}, s{v.s}, data{v.data+off_arg*v.s}
+ConstVector::ConstVector(const ConstVector& v, int off_arg, int l) :
+    len {l}, s {v.s}, data {v.data + off_arg * v.s}
 {
   if (off_arg < 0 || off_arg + len > v.len)
     throw SYLV_MES_EXCEPTION("Subvector not contained in supvector.");
 }
 
-ConstVector::ConstVector(const ConstVector &v, int off_arg, int skip, int l)
-  : len(l), s{v.s*skip}, data{v.data+off_arg*v.s}
+ConstVector::ConstVector(const ConstVector& v, int off_arg, int skip, int l) :
+    len(l), s {v.s * skip}, data {v.data + off_arg * v.s}
 {
 }
 
-ConstVector::ConstVector(const double *d, int skip, int l)
-  : len{l}, s{skip}, data{d}
+ConstVector::ConstVector(const double* d, int skip, int l) : len {l}, s {skip}, data {d}
 {
 }
 
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-ConstVector::ConstVector(const mxArray *p)
-  : len{static_cast<int>(mxGetNumberOfElements(p))},
-    data{mxGetPr(p)}
+ConstVector::ConstVector(const mxArray* p) :
+    len {static_cast<int>(mxGetNumberOfElements(p))}, data {mxGetPr(p)}
 {
   if (!mxIsDouble(p))
     throw SYLV_MES_EXCEPTION("This is not a MATLAB array of doubles.");
@@ -324,7 +314,7 @@ ConstVector::ConstVector(const mxArray *p)
 #endif
 
 bool
-ConstVector::operator==(const ConstVector &y) const
+ConstVector::operator==(const ConstVector& y) const
 {
   if (len != y.len)
     return false;
@@ -337,7 +327,7 @@ ConstVector::operator==(const ConstVector &y) const
 }
 
 bool
-ConstVector::operator<(const ConstVector &y) const
+ConstVector::operator<(const ConstVector& y) const
 {
   int i = std::min(len, y.len);
   int ii = 0;
@@ -354,7 +344,7 @@ ConstVector::getNorm() const
 {
   double s = 0;
   for (int i = 0; i < len; i++)
-    s += operator[](i)*operator[](i);
+    s += operator[](i) * operator[](i);
   return sqrt(s);
 }
 
@@ -377,7 +367,7 @@ ConstVector::getNorm1() const
 }
 
 double
-ConstVector::dot(const ConstVector &y) const
+ConstVector::dot(const ConstVector& y) const
 {
   if (len != y.len)
     throw SYLV_MES_EXCEPTION("Vector has different length in ConstVector::dot.");
diff --git a/mex/sources/libkorder/sylv/Vector.hh b/mex/sources/libkorder/sylv/Vector.hh
index 102625c8737bd366331e70cf0cd40eb882703e4f..ecf596c6cfd6c83fedfb7994653e8f233ee3fc6b 100644
--- a/mex/sources/libkorder/sylv/Vector.hh
+++ b/mex/sources/libkorder/sylv/Vector.hh
@@ -38,62 +38,63 @@ class ConstVector;
 class Vector
 {
   friend class ConstVector;
+
 protected:
-  int len{0};
-  int s{1}; // stride (also called “skip” in some places)
-  double *data;
-  bool destroy{true};
+  int len {0};
+  int s {1}; // stride (also called “skip” in some places)
+  double* data;
+  bool destroy {true};
+
 public:
-  Vector() : data{nullptr}, destroy{false}
+  Vector() : data {nullptr}, destroy {false}
   {
   }
-  Vector(int l) : len{l}, data{new double[l]}
+  Vector(int l) : len {l}, data {new double[l]}
   {
   }
-  Vector(Vector &v) : len{v.len}, s{v.s}, data{v.data}, destroy{false}
+  Vector(Vector& v) : len {v.len}, s {v.s}, data {v.data}, destroy {false}
   {
   }
-  Vector(const Vector &v);
-  Vector(Vector &&v) : len{std::exchange(v.len, 0)}, s{v.s},
-                       data{std::exchange(v.data, nullptr)},
-                       destroy{std::exchange(v.destroy, false)}
+  Vector(const Vector& v);
+  Vector(Vector&& v) :
+      len {std::exchange(v.len, 0)}, s {v.s}, data {std::exchange(v.data, nullptr)},
+      destroy {std::exchange(v.destroy, false)}
   {
   }
   // We don't want implict conversion from ConstVector, since it’s expensive
-  explicit Vector(const ConstVector &v);
-  Vector(double *d, int l)
-    : len(l), data{d}, destroy{false}
+  explicit Vector(const ConstVector& v);
+  Vector(double* d, int l) : len(l), data {d}, destroy {false}
   {
   }
-  Vector(Vector &v, int off_arg, int l);
-  Vector(const Vector &v, int off_arg, int l);
-  Vector(Vector &v, int off_arg, int skip, int l);
-  Vector(const Vector &v, int off_arg, int skip, int l);
+  Vector(Vector& v, int off_arg, int l);
+  Vector(const Vector& v, int off_arg, int l);
+  Vector(Vector& v, int off_arg, int skip, int l);
+  Vector(const Vector& v, int off_arg, int skip, int l);
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-  explicit Vector(mxArray *p);
+  explicit Vector(mxArray* p);
 #endif
-  Vector &operator=(const Vector &v);
+  Vector& operator=(const Vector& v);
   /* The move-assignment operator is not implemented, because moving pointers
      across class instances would break the “reference semantics” that the
      Vector class implements. The copy-assignment operator is thus used as a
      fallback. */
-  Vector &operator=(const ConstVector &v);
-  double &
+  Vector& operator=(const ConstVector& v);
+  double&
   operator[](int i)
   {
-    return data[s*i];
+    return data[s * i];
   }
-  const double &
+  const double&
   operator[](int i) const
   {
-    return data[s*i];
+    return data[s * i];
   }
-  const double *
+  const double*
   base() const
   {
     return data;
   }
-  double *
+  double*
   base()
   {
     return data;
@@ -110,13 +111,13 @@ public:
   }
 
   // Exact equality.
-  bool operator==(const Vector &y) const;
-  bool operator!=(const Vector &y) const;
+  bool operator==(const Vector& y) const;
+  bool operator!=(const Vector& y) const;
   // Lexicographic ordering.
-  bool operator<(const Vector &y) const;
-  bool operator<=(const Vector &y) const;
-  bool operator>(const Vector &y) const;
-  bool operator>=(const Vector &y) const;
+  bool operator<(const Vector& y) const;
+  bool operator<=(const Vector& y) const;
+  bool operator>(const Vector& y) const;
+  bool operator>=(const Vector& y) const;
 
   virtual ~Vector()
   {
@@ -128,18 +129,18 @@ public:
   void infs();
   void rotatePair(double alpha, double beta1, double beta2, int i);
   // Computes this = this + r·v
-  void add(double r, const Vector &v);
+  void add(double r, const Vector& v);
   // Computes this = this + r·v
-  void add(double r, const ConstVector &v);
+  void add(double r, const ConstVector& v);
   // Computes this = this + z·v (where this and v are intepreted as complex vectors)
-  void addComplex(const std::complex<double> &z, const Vector &v);
+  void addComplex(const std::complex<double>& z, const Vector& v);
   // Computes this = this + z·v (where this and v are intepreted as complex vectors)
-  void addComplex(const std::complex<double> &z, const ConstVector &v);
+  void addComplex(const std::complex<double>& z, const ConstVector& v);
   void mult(double r);
   double getNorm() const;
   double getMax() const;
   double getNorm1() const;
-  double dot(const Vector &y) const;
+  double dot(const Vector& y) const;
   bool isFinite() const;
   void print() const;
 
@@ -148,31 +149,29 @@ public:
      ⎢  ⎥=⎢      ⎥⊗I·⎢  ⎥
      ⎝x₂⎠ ⎝−β₂ α ⎠   ⎝b₂⎠
   */
-  static void mult2(double alpha, double beta1, double beta2,
-                    Vector &x1, Vector &x2,
-                    const Vector &b1, const Vector &b2);
+  static void mult2(double alpha, double beta1, double beta2, Vector& x1, Vector& x2,
+                    const Vector& b1, const Vector& b2);
   /* Computes:
      ⎛x₁⎞ ⎛x₁⎞ ⎛ α −β₁⎞   ⎛b₁⎞
      ⎢  ⎥=⎢  ⎥+⎢      ⎥⊗I·⎢  ⎥
      ⎝x₂⎠ ⎝x₂⎠ ⎝−β₂ α ⎠   ⎝b₂⎠
   */
-  static void mult2a(double alpha, double beta1, double beta2,
-                     Vector &x1, Vector &x2,
-                     const Vector &b1, const Vector &b2);
+  static void mult2a(double alpha, double beta1, double beta2, Vector& x1, Vector& x2,
+                     const Vector& b1, const Vector& b2);
   /* Computes:
      ⎛x₁⎞ ⎛x₁⎞ ⎛ α −β₁⎞   ⎛b₁⎞
      ⎢  ⎥=⎢  ⎥−⎢      ⎥⊗I·⎢  ⎥
      ⎝x₂⎠ ⎝x₂⎠ ⎝−β₂ α ⎠   ⎝b₂⎠
   */
   static void
-  mult2s(double alpha, double beta1, double beta2,
-         Vector &x1, Vector &x2,
-         const Vector &b1, const Vector &b2)
+  mult2s(double alpha, double beta1, double beta2, Vector& x1, Vector& x2, const Vector& b1,
+         const Vector& b2)
   {
     mult2a(-alpha, -beta1, -beta2, x1, x2, b1, b2);
   }
+
 private:
-  void copy(const double *d, int inc);
+  void copy(const double* d, int inc);
 };
 
 class ConstGeneralMatrix;
@@ -180,33 +179,35 @@ class ConstGeneralMatrix;
 class ConstVector
 {
   friend class Vector;
+
 protected:
   int len;
-  int s{1}; // stride (also called “skip” in some places)
-  const double *data;
+  int s {1}; // stride (also called “skip” in some places)
+  const double* data;
+
 public:
   // Implicit conversion from Vector is ok, since it’s cheap
-  ConstVector(const Vector &v);
-  ConstVector(const ConstVector &v) = default;
-  ConstVector(ConstVector &&v) = default;
-  ConstVector(const double *d, int l) : len{l}, data{d}
+  ConstVector(const Vector& v);
+  ConstVector(const ConstVector& v) = default;
+  ConstVector(ConstVector&& v) = default;
+  ConstVector(const double* d, int l) : len {l}, data {d}
   {
   }
-  ConstVector(const ConstVector &v, int off_arg, int l);
-  ConstVector(const ConstVector &v, int off_arg, int skip, int l);
-  ConstVector(const double *d, int skip, int l);
+  ConstVector(const ConstVector& v, int off_arg, int l);
+  ConstVector(const ConstVector& v, int off_arg, int skip, int l);
+  ConstVector(const double* d, int skip, int l);
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-  explicit ConstVector(const mxArray *p);
+  explicit ConstVector(const mxArray* p);
 #endif
   virtual ~ConstVector() = default;
-  ConstVector &operator=(const ConstVector &v) = delete;
-  ConstVector &operator=(ConstVector &&v) = delete;
-  const double &
+  ConstVector& operator=(const ConstVector& v) = delete;
+  ConstVector& operator=(ConstVector&& v) = delete;
+  const double&
   operator[](int i) const
   {
-    return data[s*i];
+    return data[s * i];
   }
-  const double *
+  const double*
   base() const
   {
     return data;
@@ -222,26 +223,26 @@ public:
     return s;
   }
   // Exact equality
-  bool operator==(const ConstVector &y) const;
+  bool operator==(const ConstVector& y) const;
   bool
-  operator!=(const ConstVector &y) const
+  operator!=(const ConstVector& y) const
   {
     return !operator==(y);
   }
   // Lexicographic ordering
-  bool operator<(const ConstVector &y) const;
+  bool operator<(const ConstVector& y) const;
   bool
-  operator<=(const ConstVector &y) const
+  operator<=(const ConstVector& y) const
   {
     return operator<(y) || operator==(y);
   }
   bool
-  operator>(const ConstVector &y) const
+  operator>(const ConstVector& y) const
   {
     return !operator<=(y);
   }
   bool
-  operator>=(const ConstVector &y) const
+  operator>=(const ConstVector& y) const
   {
     return !operator<(y);
   }
@@ -249,7 +250,7 @@ public:
   double getNorm() const;
   double getMax() const;
   double getNorm1() const;
-  double dot(const ConstVector &y) const;
+  double dot(const ConstVector& y) const;
   bool isFinite() const;
   void print() const;
 };
diff --git a/mex/sources/libkorder/sylv/tests/MMMatrix.cc b/mex/sources/libkorder/sylv/tests/MMMatrix.cc
index e3c8f8a7fc908c035ab1931d856389a1509d0f30..8f6de6f54338370c93d962dafdd658753d2cd26b 100644
--- a/mex/sources/libkorder/sylv/tests/MMMatrix.cc
+++ b/mex/sources/libkorder/sylv/tests/MMMatrix.cc
@@ -23,11 +23,11 @@
 #include <fstream>
 #include <iomanip>
 
-MMMatrixIn::MMMatrixIn(const std::string &fname)
+MMMatrixIn::MMMatrixIn(const std::string& fname)
 {
-  std::ifstream fd{fname};
+  std::ifstream fd {fname};
   if (fd.fail())
-    throw MMException("Cannot open file "+fname+" for reading\n");
+    throw MMException("Cannot open file " + fname + " for reading\n");
 
   // jump over initial comments
   while (fd.peek() == '%')
@@ -38,7 +38,7 @@ MMMatrixIn::MMMatrixIn(const std::string &fname)
   if (fd.fail())
     throw MMException("Couldn't parse rows and cols\n");
   // read in data
-  int len = rows*cols;
+  int len = rows * cols;
   data.resize(len);
   int i = 0;
   while (!fd.eof() && i < len)
@@ -55,11 +55,11 @@ MMMatrixIn::MMMatrixIn(const std::string &fname)
 }
 
 void
-MMMatrixOut::write(const std::string &fname, const GeneralMatrix &m)
+MMMatrixOut::write(const std::string& fname, const GeneralMatrix& m)
 {
-  std::ofstream fd{fname, std::ios::out | std::ios::trunc};
+  std::ofstream fd {fname, std::ios::out | std::ios::trunc};
   if (fd.fail())
-    throw MMException("Cannot open file "+fname+" for writing\n");
+    throw MMException("Cannot open file " + fname + " for writing\n");
 
   fd << "%%%%MatrixMarket matrix array real general" << std::endl
      << m.nrows() << ' ' << m.ncols() << std::endl
diff --git a/mex/sources/libkorder/sylv/tests/MMMatrix.hh b/mex/sources/libkorder/sylv/tests/MMMatrix.hh
index e3d34f615e84a1bddffedb899a3e7ee2c80e5e22..59e2427bca55192434248bf4953faec1c1991806 100644
--- a/mex/sources/libkorder/sylv/tests/MMMatrix.hh
+++ b/mex/sources/libkorder/sylv/tests/MMMatrix.hh
@@ -30,6 +30,7 @@
 class MMException
 {
   std::string message;
+
 public:
   MMException(std::string mes) : message(std::move(mes))
   {
@@ -46,18 +47,19 @@ class MMMatrixIn
   std::vector<double> data;
   int rows;
   int cols;
+
 public:
-  MMMatrixIn(const std::string &fname);
+  MMMatrixIn(const std::string& fname);
   ~MMMatrixIn() = default;
   Vector
   getData()
   {
-    return Vector{data.data(), size()};
+    return Vector {data.data(), size()};
   }
   int
   size() const
   {
-    return rows*cols;
+    return rows * cols;
   }
   int
   row() const
@@ -74,7 +76,7 @@ public:
 class MMMatrixOut
 {
 public:
-  static void write(const std::string &fname, const GeneralMatrix &m);
+  static void write(const std::string& fname, const GeneralMatrix& m);
 };
 
 #endif /* MM_MATRIX_H */
diff --git a/mex/sources/libkorder/sylv/tests/tests.cc b/mex/sources/libkorder/sylv/tests/tests.cc
index b2e3628bae978c0cebf814860002c8f753072664..4175790f8a72c8cc889bf26b06000335124c5175 100644
--- a/mex/sources/libkorder/sylv/tests/tests.cc
+++ b/mex/sources/libkorder/sylv/tests/tests.cc
@@ -18,29 +18,29 @@
  * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#include "SylvException.hh"
+#include "GeneralSylvester.hh"
+#include "IterativeSylvester.hh"
+#include "KronUtils.hh"
+#include "KronVector.hh"
 #include "QuasiTriangular.hh"
 #include "QuasiTriangularZero.hh"
-#include "Vector.hh"
-#include "KronVector.hh"
-#include "KronUtils.hh"
-#include "TriangularSylvester.hh"
-#include "GeneralSylvester.hh"
 #include "SchurDecompEig.hh"
 #include "SimilarityDecomp.hh"
-#include "IterativeSylvester.hh"
+#include "SylvException.hh"
 #include "SylvMatrix.hh"
+#include "TriangularSylvester.hh"
+#include "Vector.hh"
 #include "int_power.hh"
 
 #include "MMMatrix.hh"
 
-#include <ctime>
 #include <cmath>
-#include <string>
-#include <utility>
-#include <iostream>
+#include <ctime>
 #include <iomanip>
+#include <iostream>
 #include <memory>
+#include <string>
+#include <utility>
 
 class TestRunnable
 {
@@ -53,30 +53,31 @@ public:
   virtual ~TestRunnable() = default;
   bool test() const;
   virtual bool run() const = 0;
+
 protected:
   // declaration of auxiliary static methods
-  static bool quasi_solve(bool trans, const std::string &mname, const std::string &vname);
-  static bool mult_kron(bool trans, const std::string &mname, const std::string &vname,
-                        const std::string &cname, int m, int n, int depth);
-  static bool level_kron(bool trans, const std::string &mname, const std::string &vname,
-                         const std::string &cname, int level, int m, int n, int depth);
-  static bool kron_power(const std::string &m1name, const std::string &m2name, const std::string &vname,
-                         const std::string &cname, int m, int n, int depth);
-  static bool lin_eval(const std::string &m1name, const std::string &m2name, const std::string &vname,
-                       const std::string &cname, int m, int n, int depth,
+  static bool quasi_solve(bool trans, const std::string& mname, const std::string& vname);
+  static bool mult_kron(bool trans, const std::string& mname, const std::string& vname,
+                        const std::string& cname, int m, int n, int depth);
+  static bool level_kron(bool trans, const std::string& mname, const std::string& vname,
+                         const std::string& cname, int level, int m, int n, int depth);
+  static bool kron_power(const std::string& m1name, const std::string& m2name,
+                         const std::string& vname, const std::string& cname, int m, int n,
+                         int depth);
+  static bool lin_eval(const std::string& m1name, const std::string& m2name,
+                       const std::string& vname, const std::string& cname, int m, int n, int depth,
                        double alpha, double beta1, double beta2);
-  static bool qua_eval(const std::string &m1name, const std::string &m2name, const std::string &vname,
-                       const std::string &cname, int m, int n, int depth,
-                       double alpha, double betas, double gamma,
-                       double delta1, double delta2);
-  static bool tri_sylv(const std::string &m1name, const std::string &m2name, const std::string &vname,
-                       int m, int n, int depth);
-  static bool gen_sylv(const std::string &aname, const std::string &bname, const std::string &cname,
-                       const std::string &dname, int m, int n, int order);
-  static bool eig_bubble(const std::string &aname, int from, int to);
-  static bool block_diag(const std::string &aname, double log10norm = 3.0);
-  static bool iter_sylv(const std::string &m1name, const std::string &m2name, const std::string &vname,
-                        int m, int n, int depth);
+  static bool qua_eval(const std::string& m1name, const std::string& m2name,
+                       const std::string& vname, const std::string& cname, int m, int n, int depth,
+                       double alpha, double betas, double gamma, double delta1, double delta2);
+  static bool tri_sylv(const std::string& m1name, const std::string& m2name,
+                       const std::string& vname, int m, int n, int depth);
+  static bool gen_sylv(const std::string& aname, const std::string& bname, const std::string& cname,
+                       const std::string& dname, int m, int n, int order);
+  static bool eig_bubble(const std::string& aname, int from, int to);
+  static bool block_diag(const std::string& aname, double log10norm = 3.0);
+  static bool iter_sylv(const std::string& m1name, const std::string& m2name,
+                        const std::string& vname, int m, int n, int depth);
 };
 
 bool
@@ -86,7 +87,8 @@ TestRunnable::test() const
   clock_t start = clock();
   bool passed = run();
   clock_t end = clock();
-  std::cout << "CPU time " << (static_cast<double>(end-start))/CLOCKS_PER_SEC << " (CPU seconds)..................";
+  std::cout << "CPU time " << (static_cast<double>(end - start)) / CLOCKS_PER_SEC
+            << " (CPU seconds)..................";
   if (passed)
     std::cout << "passed";
   else
@@ -100,7 +102,7 @@ TestRunnable::test() const
 /**********************************************************/
 
 bool
-TestRunnable::quasi_solve(bool trans, const std::string &mname, const std::string &vname)
+TestRunnable::quasi_solve(bool trans, const std::string& mname, const std::string& vname)
 {
   MMMatrixIn mmt(mname);
   MMMatrixIn mmv(vname);
@@ -114,15 +116,16 @@ TestRunnable::quasi_solve(bool trans, const std::string &mname, const std::strin
     }
   else if (mmt.row() > mmt.col())
     {
-      t = std::make_unique<QuasiTriangularZero>(mmt.row()-mmt.col(), mmt.getData(), mmt.col());
-      tsave = std::make_unique<QuasiTriangularZero>(const_cast<const QuasiTriangularZero &>(dynamic_cast<QuasiTriangularZero &>(*t)));
+      t = std::make_unique<QuasiTriangularZero>(mmt.row() - mmt.col(), mmt.getData(), mmt.col());
+      tsave = std::make_unique<QuasiTriangularZero>(
+          const_cast<const QuasiTriangularZero&>(dynamic_cast<QuasiTriangularZero&>(*t)));
     }
   else
     {
       std::cout << "  Wrong quasi triangular dimensions, rows must be >= cols.\n";
       return false;
     }
-  ConstVector v{mmv.getData()};
+  ConstVector v {mmv.getData()};
   Vector x(v.length());
   double eig_min = 1.0e20;
   if (trans)
@@ -143,29 +146,26 @@ TestRunnable::quasi_solve(bool trans, const std::string &mname, const std::strin
 }
 
 bool
-TestRunnable::mult_kron(bool trans, const std::string &mname, const std::string &vname,
-                        const std::string &cname, int m, int n, int depth)
+TestRunnable::mult_kron(bool trans, const std::string& mname, const std::string& vname,
+                        const std::string& cname, int m, int n, int depth)
 {
   MMMatrixIn mmt(mname);
   MMMatrixIn mmv(vname);
   MMMatrixIn mmc(cname);
 
-  int length = power(m, depth)*n;
-  if (mmt.row() != m
-      || mmv.row() != length
-      || mmc.row() != length)
+  int length = power(m, depth) * n;
+  if (mmt.row() != m || mmv.row() != length || mmc.row() != length)
     {
       std::cout << "  Incompatible sizes for kron mult action, len=" << length
-                << ", matrow=" << mmt.row() << ", m=" << m
-                << ", vrow=" << mmv.row() << ", crow=" << mmc.row()
-                << std::endl;
+                << ", matrow=" << mmt.row() << ", m=" << m << ", vrow=" << mmv.row()
+                << ", crow=" << mmc.row() << std::endl;
       return false;
     }
 
   QuasiTriangular t(mmt.getData(), mmt.row());
-  Vector vraw{mmv.getData()};
+  Vector vraw {mmv.getData()};
   KronVector v(vraw, m, n, depth);
-  Vector craw{mmc.getData()};
+  Vector craw {mmc.getData()};
   KronVector c(craw, m, n, depth);
   if (trans)
     t.multKronTrans(v);
@@ -178,30 +178,27 @@ TestRunnable::mult_kron(bool trans, const std::string &mname, const std::string
 }
 
 bool
-TestRunnable::level_kron(bool trans, const std::string &mname, const std::string &vname,
-                         const std::string &cname, int level, int m, int n, int depth)
+TestRunnable::level_kron(bool trans, const std::string& mname, const std::string& vname,
+                         const std::string& cname, int level, int m, int n, int depth)
 {
   MMMatrixIn mmt(mname);
   MMMatrixIn mmv(vname);
   MMMatrixIn mmc(cname);
 
-  int length = power(m, depth)*n;
-  if ((level > 0 && mmt.row() != m)
-      || (level == 0 && mmt.row() != n)
-      || mmv.row() != length
+  int length = power(m, depth) * n;
+  if ((level > 0 && mmt.row() != m) || (level == 0 && mmt.row() != n) || mmv.row() != length
       || mmc.row() != length)
     {
       std::cout << "  Incompatible sizes for kron mult action, len=" << length
-                << ", matrow=" << mmt.row() << ", m=" << m << ", n=" << n
-                << ", vrow=" << mmv.row() << ", crow=" << mmc.row()
-                << std::endl;
+                << ", matrow=" << mmt.row() << ", m=" << m << ", n=" << n << ", vrow=" << mmv.row()
+                << ", crow=" << mmc.row() << std::endl;
       return false;
     }
 
   QuasiTriangular t(mmt.getData(), mmt.row());
-  Vector vraw{mmv.getData()};
+  Vector vraw {mmv.getData()};
   ConstKronVector v(vraw, m, n, depth);
-  Vector craw{mmc.getData()};
+  Vector craw {mmc.getData()};
   KronVector c(craw, m, n, depth);
   KronVector x(v);
   if (trans)
@@ -215,33 +212,29 @@ TestRunnable::level_kron(bool trans, const std::string &mname, const std::string
 }
 
 bool
-TestRunnable::kron_power(const std::string &m1name, const std::string &m2name, const std::string &vname,
-                         const std::string &cname, int m, int n, int depth)
+TestRunnable::kron_power(const std::string& m1name, const std::string& m2name,
+                         const std::string& vname, const std::string& cname, int m, int n,
+                         int depth)
 {
   MMMatrixIn mmt1(m1name);
   MMMatrixIn mmt2(m2name);
   MMMatrixIn mmv(vname);
   MMMatrixIn mmc(cname);
 
-  int length = power(m, depth)*n;
-  if (mmt1.row() != m
-      || mmt2.row() != n
-      || mmv.row() != length
-      || mmc.row() != length)
+  int length = power(m, depth) * n;
+  if (mmt1.row() != m || mmt2.row() != n || mmv.row() != length || mmc.row() != length)
     {
       std::cout << "  Incompatible sizes for kron power mult action, len=" << length
-                << ", row1=" << mmt1.row() << ", row2=" << mmt2.row()
-                << ", m=" << m << ", n=" << n
-                << ", vrow=" << mmv.row() << ", crow=" << mmc.row()
-                << std::endl;
+                << ", row1=" << mmt1.row() << ", row2=" << mmt2.row() << ", m=" << m << ", n=" << n
+                << ", vrow=" << mmv.row() << ", crow=" << mmc.row() << std::endl;
       return false;
     }
 
   QuasiTriangular t1(mmt1.getData(), mmt1.row());
   QuasiTriangular t2(mmt2.getData(), mmt2.row());
-  Vector vraw{mmv.getData()};
+  Vector vraw {mmv.getData()};
   ConstKronVector v(vraw, m, n, depth);
-  Vector craw{mmc.getData()};
+  Vector craw {mmc.getData()};
   KronVector c(craw, m, n, depth);
   KronVector x(v);
   KronUtils::multKron(t1, t2, x);
@@ -252,8 +245,8 @@ TestRunnable::kron_power(const std::string &m1name, const std::string &m2name, c
 }
 
 bool
-TestRunnable::lin_eval(const std::string &m1name, const std::string &m2name, const std::string &vname,
-                       const std::string &cname, int m, int n, int depth,
+TestRunnable::lin_eval(const std::string& m1name, const std::string& m2name,
+                       const std::string& vname, const std::string& cname, int m, int n, int depth,
                        double alpha, double beta1, double beta2)
 {
   MMMatrixIn mmt1(m1name);
@@ -261,30 +254,25 @@ TestRunnable::lin_eval(const std::string &m1name, const std::string &m2name, con
   MMMatrixIn mmv(vname);
   MMMatrixIn mmc(cname);
 
-  int length = power(m, depth)*n;
-  if (mmt1.row() != m
-      || mmt2.row() != n
-      || mmv.row() != 2*length
-      || mmc.row() != 2*length)
+  int length = power(m, depth) * n;
+  if (mmt1.row() != m || mmt2.row() != n || mmv.row() != 2 * length || mmc.row() != 2 * length)
     {
       std::cout << "  Incompatible sizes for lin eval action, len=" << length
-                << ", row1=" << mmt1.row() << ", row2=" << mmt2.row()
-                << ", m=" << m << ", n=" << n
-                << ", vrow=" << mmv.row() << ", crow=" << mmc.row()
-                << std::endl;
+                << ", row1=" << mmt1.row() << ", row2=" << mmt2.row() << ", m=" << m << ", n=" << n
+                << ", vrow=" << mmv.row() << ", crow=" << mmc.row() << std::endl;
       return false;
     }
 
   QuasiTriangular t1(mmt1.getData(), mmt1.row());
   QuasiTriangular t2(mmt2.getData(), mmt2.row());
   TriangularSylvester ts(t2, t1);
-  ConstVector vraw1{mmv.getData(), 0, length};
+  ConstVector vraw1 {mmv.getData(), 0, length};
   ConstKronVector v1(vraw1, m, n, depth);
-  ConstVector vraw2{mmv.getData(), length, length};
+  ConstVector vraw2 {mmv.getData(), length, length};
   ConstKronVector v2(vraw2, m, n, depth);
-  ConstVector craw1{mmc.getData(), 0, length};
+  ConstVector craw1 {mmc.getData(), 0, length};
   ConstKronVector c1(craw1, m, n, depth);
-  ConstVector craw2{mmc.getData(), length, length};
+  ConstVector craw2 {mmc.getData(), length, length};
   ConstKronVector c2(craw2, m, n, depth);
   KronVector x1(m, n, depth);
   KronVector x2(m, n, depth);
@@ -294,44 +282,38 @@ TestRunnable::lin_eval(const std::string &m1name, const std::string &m2name, con
   double norm1 = x1.getNorm();
   double norm2 = x2.getNorm();
   std::cout << "\terror norm1 = " << norm1 << "\n\terror norm2 = " << norm2 << '\n';
-  return (norm1*norm1+norm2*norm2 < eps_norm*eps_norm);
+  return (norm1 * norm1 + norm2 * norm2 < eps_norm * eps_norm);
 }
 
 bool
-TestRunnable::qua_eval(const std::string &m1name, const std::string &m2name, const std::string &vname,
-                       const std::string &cname, int m, int n, int depth,
-                       double alpha, double betas, double gamma,
-                       double delta1, double delta2)
+TestRunnable::qua_eval(const std::string& m1name, const std::string& m2name,
+                       const std::string& vname, const std::string& cname, int m, int n, int depth,
+                       double alpha, double betas, double gamma, double delta1, double delta2)
 {
   MMMatrixIn mmt1(m1name);
   MMMatrixIn mmt2(m2name);
   MMMatrixIn mmv(vname);
   MMMatrixIn mmc(cname);
 
-  int length = power(m, depth)*n;
-  if (mmt1.row() != m
-      || mmt2.row() != n
-      || mmv.row() != 2*length
-      || mmc.row() != 2*length)
+  int length = power(m, depth) * n;
+  if (mmt1.row() != m || mmt2.row() != n || mmv.row() != 2 * length || mmc.row() != 2 * length)
     {
       std::cout << "  Incompatible sizes for qua eval action, len=" << length
-                << ", row1=" << mmt1.row() << ", row2=" << mmt2.row()
-                << ", m=" << m << ", n=" << n
-                << ", vrow=" << mmv.row() << ", crow=" << mmc.row()
-                << std::endl;
+                << ", row1=" << mmt1.row() << ", row2=" << mmt2.row() << ", m=" << m << ", n=" << n
+                << ", vrow=" << mmv.row() << ", crow=" << mmc.row() << std::endl;
       return false;
     }
 
   QuasiTriangular t1(mmt1.getData(), mmt1.row());
   QuasiTriangular t2(mmt2.getData(), mmt2.row());
   TriangularSylvester ts(t2, t1);
-  ConstVector vraw1{mmv.getData(), 0, length};
+  ConstVector vraw1 {mmv.getData(), 0, length};
   ConstKronVector v1(vraw1, m, n, depth);
-  ConstVector vraw2{mmv.getData(), length, length};
+  ConstVector vraw2 {mmv.getData(), length, length};
   ConstKronVector v2(vraw2, m, n, depth);
-  ConstVector craw1{mmc.getData(), 0, length};
+  ConstVector craw1 {mmc.getData(), 0, length};
   ConstKronVector c1(craw1, m, n, depth);
-  ConstVector craw2{mmc.getData(), length, length};
+  ConstVector craw2 {mmc.getData(), length, length};
   ConstKronVector c2(craw2, m, n, depth);
   KronVector x1(m, n, depth);
   KronVector x2(m, n, depth);
@@ -341,86 +323,77 @@ TestRunnable::qua_eval(const std::string &m1name, const std::string &m2name, con
   double norm1 = x1.getNorm();
   double norm2 = x2.getNorm();
   std::cout << "\terror norm1 = " << norm1 << "\n\terror norm2 = " << norm2 << std::endl;
-  return (norm1*norm1+norm2*norm2 < 100*eps_norm*eps_norm); // relax norm
+  return (norm1 * norm1 + norm2 * norm2 < 100 * eps_norm * eps_norm); // relax norm
 }
 
 bool
-TestRunnable::tri_sylv(const std::string &m1name, const std::string &m2name, const std::string &vname,
-                       int m, int n, int depth)
+TestRunnable::tri_sylv(const std::string& m1name, const std::string& m2name,
+                       const std::string& vname, int m, int n, int depth)
 {
   MMMatrixIn mmt1(m1name);
   MMMatrixIn mmt2(m2name);
   MMMatrixIn mmv(vname);
 
-  int length = power(m, depth)*n;
-  if (mmt1.row() != m
-      || mmt2.row() != n
-      || mmv.row() != length)
+  int length = power(m, depth) * n;
+  if (mmt1.row() != m || mmt2.row() != n || mmv.row() != length)
     {
       std::cout << "  Incompatible sizes for triangular sylvester action, len=" << length
-                << ", row1=" << mmt1.row() << ", row2=" << mmt2.row()
-                << ", m=" << m << ", n=" << n
-                << ", vrow=" << mmv.row()
-                << std::endl;
+                << ", row1=" << mmt1.row() << ", row2=" << mmt2.row() << ", m=" << m << ", n=" << n
+                << ", vrow=" << mmv.row() << std::endl;
       return false;
     }
 
   QuasiTriangular t1(mmt1.getData(), mmt1.row());
   QuasiTriangular t2(mmt2.getData(), mmt2.row());
   TriangularSylvester ts(t2, t1);
-  Vector vraw{mmv.getData()};
+  Vector vraw {mmv.getData()};
   ConstKronVector v(vraw, m, n, depth);
   KronVector d(v); // copy of v
   SylvParams pars;
   ts.solve(pars, d);
   pars.print("\t");
-  KronVector dcheck(const_cast<const KronVector &>(d));
+  KronVector dcheck(const_cast<const KronVector&>(d));
   KronUtils::multKron(t1, t2, dcheck);
   dcheck.add(1.0, d);
   dcheck.add(-1.0, v);
   double norm = dcheck.getNorm();
   double xnorm = v.getNorm();
-  std::cout << "\trel. error norm = " << norm/xnorm << std::endl;
+  std::cout << "\trel. error norm = " << norm / xnorm << std::endl;
   double max = dcheck.getMax();
   double xmax = v.getMax();
-  std::cout << "\trel. error max = " << max/xmax << std::endl;
-  return (norm < xnorm*eps_norm);
+  std::cout << "\trel. error max = " << max / xmax << std::endl;
+  return (norm < xnorm * eps_norm);
 }
 
 bool
-TestRunnable::gen_sylv(const std::string &aname, const std::string &bname, const std::string &cname,
-                       const std::string &dname, int m, int n, int order)
+TestRunnable::gen_sylv(const std::string& aname, const std::string& bname, const std::string& cname,
+                       const std::string& dname, int m, int n, int order)
 {
   MMMatrixIn mma(aname);
   MMMatrixIn mmb(bname);
   MMMatrixIn mmc(cname);
   MMMatrixIn mmd(dname);
 
-  if (m != mmc.row() || m != mmc.col()
-      || n != mma.row() || n != mma.col()
-      || n != mmb.row() || n < mmb.col()
-      || n != mmd.row() || power(m, order) != mmd.col())
+  if (m != mmc.row() || m != mmc.col() || n != mma.row() || n != mma.col() || n != mmb.row()
+      || n < mmb.col() || n != mmd.row() || power(m, order) != mmd.col())
     {
       std::cout << "  Incompatible sizes for gen_sylv.\n";
       return false;
     }
 
   SylvParams ps(true);
-  GeneralSylvester gs(order, n, m, n-mmb.col(),
-                      mma.getData(), mmb.getData(),
-                      mmc.getData(), mmd.getData(),
-                      ps);
+  GeneralSylvester gs(order, n, m, n - mmb.col(), mma.getData(), mmb.getData(), mmc.getData(),
+                      mmd.getData(), ps);
   gs.solve();
   gs.check(mmd.getData());
-  const SylvParams &pars = gs.getParams();
+  const SylvParams& pars = gs.getParams();
   pars.print("\t");
-  return (*(pars.mat_err1) < eps_norm && *(pars.mat_errI) < eps_norm
-          && *(pars.mat_errF) < eps_norm && *(pars.vec_err1) < eps_norm
-          && *(pars.vec_errI) < eps_norm);
+  return (*(pars.mat_err1) < eps_norm && *(pars.mat_errI) < eps_norm && *(pars.mat_errF) < eps_norm
+          && *(pars.vec_err1) < eps_norm && *(pars.vec_errI) < eps_norm);
 }
 
 bool
-TestRunnable::eig_bubble(const std::string &aname, int from, int to)
+TestRunnable::eig_bubble(const std::string& aname, int from, int to)
 {
   MMMatrixIn mma(aname);
 
@@ -432,7 +405,7 @@ TestRunnable::eig_bubble(const std::string &aname, int from, int to)
 
   int n = mma.row();
   QuasiTriangular orig(mma.getData(), n);
-  SchurDecompEig dec(const_cast<const QuasiTriangular &>(orig));
+  SchurDecompEig dec(const_cast<const QuasiTriangular&>(orig));
   QuasiTriangular::diag_iter itf = dec.getT().diag_begin();
   QuasiTriangular::diag_iter itt = dec.getT().diag_begin();
   for (int i = 0; i < from; i++)
@@ -449,13 +422,13 @@ TestRunnable::eig_bubble(const std::string &aname, int from, int to)
   double onormInf = orig.getNormInf();
   std::cout << "\tabs. error1 = " << norm1 << std::endl
             << "\tabs. error∞ = " << normInf << std::endl
-            << "\trel. error1 = " << norm1/onorm1 << std::endl
-            << "\trel. error∞ = " << normInf/onormInf << std::endl;
-  return (norm1 < eps_norm*onorm1 && normInf < eps_norm*onormInf);
+            << "\trel. error1 = " << norm1 / onorm1 << std::endl
+            << "\trel. error∞ = " << normInf / onormInf << std::endl;
+  return (norm1 < eps_norm * onorm1 && normInf < eps_norm * onormInf);
 }
 
 bool
-TestRunnable::block_diag(const std::string &aname, double log10norm)
+TestRunnable::block_diag(const std::string& aname, double log10norm)
 {
   MMMatrixIn mma(aname);
 
@@ -479,8 +452,8 @@ TestRunnable::block_diag(const std::string &aname, double log10norm)
   std::cout << "\terror Q·B·Q⁻¹:" << std::endl
             << "\tabs. error1 = " << norm1 << std::endl
             << "\tabs. error∞ = " << normInf << std::endl
-            << "\trel. error1 = " << norm1/onorm1 << std::endl
-            << "\trel. error∞ = " << normInf/onormInf << std::endl;
+            << "\trel. error1 = " << norm1 / onorm1 << std::endl
+            << "\trel. error∞ = " << normInf / onormInf << std::endl;
   SqSylvMatrix check2(dec.getQ() * dec.getInvQ());
   SqSylvMatrix in(n);
   in.setUnit();
@@ -490,51 +463,47 @@ TestRunnable::block_diag(const std::string &aname, double log10norm)
   std::cout << "\terror Q·Q⁻¹:" << std::endl
             << "\tabs. error1 = " << nor1 << std::endl
             << "\tabs. error∞ = " << norInf << std::endl;
-  return (norm1 < eps_norm*pow(10, log10norm)*onorm1);
+  return (norm1 < eps_norm * pow(10, log10norm) * onorm1);
 }
 
 bool
-TestRunnable::iter_sylv(const std::string &m1name, const std::string &m2name, const std::string &vname,
-                        int m, int n, int depth)
+TestRunnable::iter_sylv(const std::string& m1name, const std::string& m2name,
+                        const std::string& vname, int m, int n, int depth)
 {
   MMMatrixIn mmt1(m1name);
   MMMatrixIn mmt2(m2name);
   MMMatrixIn mmv(vname);
 
-  int length = power(m, depth)*n;
-  if (mmt1.row() != m
-      || mmt2.row() != n
-      || mmv.row() != length)
+  int length = power(m, depth) * n;
+  if (mmt1.row() != m || mmt2.row() != n || mmv.row() != length)
     {
       std::cout << "  Incompatible sizes for triangular sylvester iteration, len=" << length
-                << ", row1=" << mmt1.row() << ", row2=" << mmt2.row()
-                << ", m=" << m << ", n=" << n
-                << ", vrow=" << mmv.row()
-                << std::endl;
+                << ", row1=" << mmt1.row() << ", row2=" << mmt2.row() << ", m=" << m << ", n=" << n
+                << ", vrow=" << mmv.row() << std::endl;
       return false;
     }
 
   QuasiTriangular t1(mmt1.getData(), mmt1.row());
   QuasiTriangular t2(mmt2.getData(), mmt2.row());
   IterativeSylvester is(t2, t1);
-  Vector vraw{mmv.getData()};
+  Vector vraw {mmv.getData()};
   ConstKronVector v(vraw, m, n, depth);
   KronVector d(v); // copy of v
   SylvParams pars;
   pars.method = SylvParams::solve_method::iter;
   is.solve(pars, d);
   pars.print("\t");
-  KronVector dcheck(const_cast<const KronVector &>(d));
+  KronVector dcheck(const_cast<const KronVector&>(d));
   KronUtils::multKron(t1, t2, dcheck);
   dcheck.add(1.0, d);
   dcheck.add(-1.0, v);
   double cnorm = dcheck.getNorm();
   double xnorm = v.getNorm();
-  std::cout << "\trel. error norm = " << cnorm/xnorm << std::endl;
+  std::cout << "\trel. error norm = " << cnorm / xnorm << std::endl;
   double max = dcheck.getMax();
   double xmax = v.getMax();
-  std::cout << "\trel. error max = " << max/xmax << std::endl;
-  return (cnorm < xnorm*eps_norm);
+  std::cout << "\trel. error max = " << max / xmax << std::endl;
+  return (cnorm < xnorm * eps_norm);
 }
 
 /**********************************************************/
@@ -1018,29 +987,25 @@ KronPowerTest::run() const
 bool
 SmallLinEvalTest::run() const
 {
-  return lin_eval("qt2x2.mm", "qt3x3.mm", "v24.mm", "vcheck24.mm", 2, 3, 2,
-                  2, 1, 3);
+  return lin_eval("qt2x2.mm", "qt3x3.mm", "v24.mm", "vcheck24.mm", 2, 3, 2, 2, 1, 3);
 }
 
 bool
 LinEvalTest::run() const
 {
-  return lin_eval("qt7x7.mm", "tr5x5.mm", "v490.mm", "vcheck490.mm", 7, 5, 2,
-                  2, 1, 3);
+  return lin_eval("qt7x7.mm", "tr5x5.mm", "v490.mm", "vcheck490.mm", 7, 5, 2, 2, 1, 3);
 }
 
 bool
 SmallQuaEvalTest::run() const
 {
-  return qua_eval("qt2x2.mm", "qt3x3.mm", "v24.mm", "vcheck24q.mm", 2, 3, 2,
-                  -0.5, 3, 2, 1, 3);
+  return qua_eval("qt2x2.mm", "qt3x3.mm", "v24.mm", "vcheck24q.mm", 2, 3, 2, -0.5, 3, 2, 1, 3);
 }
 
 bool
 QuaEvalTest::run() const
 {
-  return qua_eval("qt7x7.mm", "tr5x5.mm", "v490.mm", "vcheck490q.mm", 7, 5, 2,
-                  -0.5, 3, 2, 1, 3);
+  return qua_eval("qt7x7.mm", "tr5x5.mm", "v490.mm", "vcheck490q.mm", 7, 5, 2, -0.5, 3, 2, 1, 3);
 }
 
 bool
@@ -1204,18 +1169,18 @@ main()
   // launch the tests
   std::cout << std::setprecision(4);
   int success = 0;
-  for (const auto &test : all_tests)
+  for (const auto& test : all_tests)
     {
       try
         {
           if (test->test())
             success++;
         }
-      catch (const MMException &e)
+      catch (const MMException& e)
         {
           std::cout << "Caught MM exception in <" << test->name << ">:\n" << e.getMessage();
         }
-      catch (SylvException &e)
+      catch (SylvException& e)
         {
           std::cout << "Caught Sylv exception in " << test->name << ":\n";
           e.printMessage();
@@ -1223,8 +1188,8 @@ main()
     }
 
   int nfailed = all_tests.size() - success;
-  std::cout << "There were " << nfailed << " tests that failed out of "
-            << all_tests.size() << " tests run." << std::endl;
+  std::cout << "There were " << nfailed << " tests that failed out of " << all_tests.size()
+            << " tests run." << std::endl;
 
   if (nfailed)
     return EXIT_FAILURE;
diff --git a/mex/sources/libkorder/tl/equivalence.cc b/mex/sources/libkorder/tl/equivalence.cc
index b607594010d3f80803a195579c406bae98a03482..9b8f4de5a5684b70ec1defef3b7dfc3fd5a565c1 100644
--- a/mex/sources/libkorder/tl/equivalence.cc
+++ b/mex/sources/libkorder/tl/equivalence.cc
@@ -27,8 +27,7 @@
 int
 OrdSequence::operator[](int i) const
 {
-  TL_RAISE_IF((i < 0 || i >= length()),
-              "Index out of range in OrdSequence::operator[]");
+  TL_RAISE_IF((i < 0 || i >= length()), "Index out of range in OrdSequence::operator[]");
   return data[i];
 }
 
@@ -37,7 +36,7 @@ OrdSequence::operator[](int i) const
    according to the average, and then according to the first item. */
 
 bool
-OrdSequence::operator<(const OrdSequence &s) const
+OrdSequence::operator<(const OrdSequence& s) const
 {
   double ta = average();
   double sa = s.average();
@@ -45,7 +44,7 @@ OrdSequence::operator<(const OrdSequence &s) const
 }
 
 bool
-OrdSequence::operator==(const OrdSequence &s) const
+OrdSequence::operator==(const OrdSequence& s) const
 {
   if (length() != s.length())
     return false;
@@ -73,7 +72,7 @@ OrdSequence::add(int i)
 }
 
 void
-OrdSequence::add(const OrdSequence &s)
+OrdSequence::add(const OrdSequence& s)
 {
   auto vit = s.data.begin();
   while (vit != s.data.end())
@@ -104,14 +103,13 @@ OrdSequence::average() const
   double res = 0;
   for (int i : data)
     res += i;
-  TL_RAISE_IF(data.size() == 0,
-              "Attempt to take average of empty class in OrdSequence::average");
-  return res/data.size();
+  TL_RAISE_IF(data.size() == 0, "Attempt to take average of empty class in OrdSequence::average");
+  return res / data.size();
 }
 
 /* Debug print. */
 void
-OrdSequence::print(const std::string &prefix) const
+OrdSequence::print(const std::string& prefix) const
 {
   std::cout << prefix;
   for (int i : data)
@@ -119,8 +117,7 @@ OrdSequence::print(const std::string &prefix) const
   std::cout << '\n';
 }
 
-Equivalence::Equivalence(int num)
-  : n(num)
+Equivalence::Equivalence(int num) : n(num)
 {
   for (int i = 0; i < num; i++)
     {
@@ -130,8 +127,7 @@ Equivalence::Equivalence(int num)
     }
 }
 
-Equivalence::Equivalence(int num, [[maybe_unused]] const std::string &dummy)
-  : n(num)
+Equivalence::Equivalence(int num, [[maybe_unused]] const std::string& dummy) : n(num)
 {
   OrdSequence s;
   for (int i = 0; i < num; i++)
@@ -141,9 +137,7 @@ Equivalence::Equivalence(int num, [[maybe_unused]] const std::string &dummy)
 
 /* Copy constructor that also glues a given couple. */
 
-Equivalence::Equivalence(const Equivalence &e, int i1, int i2)
-  : n(e.n),
-    classes(e.classes)
+Equivalence::Equivalence(const Equivalence& e, int i1, int i2) : n(e.n), classes(e.classes)
 {
   auto s1 = find(i1);
   auto s2 = find(i2);
@@ -158,7 +152,7 @@ Equivalence::Equivalence(const Equivalence &e, int i1, int i2)
 }
 
 bool
-Equivalence::operator==(const Equivalence &e) const
+Equivalence::operator==(const Equivalence& e) const
 {
   if (!std::operator==(classes, e.classes))
     return false;
@@ -181,8 +175,7 @@ Equivalence::findHaving(int i) const
         return si;
       ++si;
     }
-  TL_RAISE_IF(si == classes.end(),
-              "Couldn't find equivalence class in Equivalence::findHaving");
+  TL_RAISE_IF(si == classes.end(), "Couldn't find equivalence class in Equivalence::findHaving");
   return si;
 }
 
@@ -196,8 +189,7 @@ Equivalence::findHaving(int i)
         return si;
       ++si;
     }
-  TL_RAISE_IF(si == classes.end(),
-              "Couldn't find equivalence class in Equivalence::findHaving");
+  TL_RAISE_IF(si == classes.end(), "Couldn't find equivalence class in Equivalence::findHaving");
   return si;
 }
 
@@ -213,8 +205,7 @@ Equivalence::find(int j) const
       ++si;
       i++;
     }
-  TL_RAISE_IF(si == classes.end(),
-              "Couldn't find equivalence class in Equivalence::find");
+  TL_RAISE_IF(si == classes.end(), "Couldn't find equivalence class in Equivalence::find");
   return si;
 }
 
@@ -228,14 +219,13 @@ Equivalence::find(int j)
       ++si;
       i++;
     }
-  TL_RAISE_IF(si == classes.end(),
-              "Couldn't find equivalence class in Equivalence::find");
+  TL_RAISE_IF(si == classes.end(), "Couldn't find equivalence class in Equivalence::find");
   return si;
 }
 
 /* Insert a new class yielding the ordering. */
 void
-Equivalence::insert(const OrdSequence &s)
+Equivalence::insert(const OrdSequence& s)
 {
   auto si = classes.begin();
   while (si != classes.end() && *si < s)
@@ -250,26 +240,23 @@ Equivalence::insert(const OrdSequence &s)
    number of classes from the beginning. */
 
 void
-Equivalence::trace(IntSequence &out, int num) const
+Equivalence::trace(IntSequence& out, int num) const
 {
   int i = 0;
   int nc = 0;
   for (auto it = begin(); it != end() && nc < num; ++it, ++nc)
     for (int j = 0; j < it->length(); j++, i++)
       {
-        TL_RAISE_IF(i >= out.size(),
-                    "Wrong size of output sequence in Equivalence::trace");
+        TL_RAISE_IF(i >= out.size(), "Wrong size of output sequence in Equivalence::trace");
         out[i] = (*it)[j];
       }
 }
 
 void
-Equivalence::trace(IntSequence &out, const Permutation &per) const
+Equivalence::trace(IntSequence& out, const Permutation& per) const
 {
-  TL_RAISE_IF(out.size() != n,
-              "Wrong size of output sequence in Equivalence::trace");
-  TL_RAISE_IF(per.size() != numClasses(),
-              "Wrong permutation for permuted Equivalence::trace");
+  TL_RAISE_IF(out.size() != n, "Wrong size of output sequence in Equivalence::trace");
+  TL_RAISE_IF(per.size() != numClasses(), "Wrong permutation for permuted Equivalence::trace");
   int i = 0;
   for (int iclass = 0; iclass < numClasses(); iclass++)
     {
@@ -281,12 +268,10 @@ Equivalence::trace(IntSequence &out, const Permutation &per) const
 
 /* Debug print. */
 void
-Equivalence::print(const std::string &prefix) const
+Equivalence::print(const std::string& prefix) const
 {
   int i = 0;
-  for (auto it = classes.begin();
-       it != classes.end();
-       ++it, i++)
+  for (auto it = classes.begin(); it != classes.end(); ++it, i++)
     {
       std::cout << prefix << "class " << i << ": ";
       it->print("");
@@ -311,8 +296,7 @@ Equivalence::print(const std::string &prefix) const
    classes. Obviously, the list is decreasing in a number of classes
    (since it is constructed by gluing attempts). */
 
-EquivalenceSet::EquivalenceSet(int num)
-  : n(num)
+EquivalenceSet::EquivalenceSet(int num) : n(num)
 {
   std::list<Equivalence> added;
   Equivalence first(n);
@@ -338,7 +322,7 @@ EquivalenceSet::EquivalenceSet(int num)
    classes to more classes. hence the reverse order. */
 
 bool
-EquivalenceSet::has(const Equivalence &e) const
+EquivalenceSet::has(const Equivalence& e) const
 {
   auto rit = equis.rbegin();
   while (rit != equis.rend() && *rit != e)
@@ -356,16 +340,14 @@ EquivalenceSet::has(const Equivalence &e) const
    be added. */
 
 void
-EquivalenceSet::addParents(const Equivalence &e,
-                           std::list<Equivalence> &added)
+EquivalenceSet::addParents(const Equivalence& e, std::list<Equivalence>& added)
 {
   if (e.numClasses() == 2 || e.numClasses() == 1)
     return;
 
   for (int i1 = 0; i1 < e.numClasses(); i1++)
-    for (int i2 = i1+1; i2 < e.numClasses(); i2++)
-      if (Equivalence ns(e, i1, i2);
-          !has(ns))
+    for (int i2 = i1 + 1; i2 < e.numClasses(); i2++)
+      if (Equivalence ns(e, i1, i2); !has(ns))
         {
           added.push_back(ns);
           equis.push_back(std::move(ns));
@@ -374,15 +356,12 @@ EquivalenceSet::addParents(const Equivalence &e,
 
 /* Debug print. */
 void
-EquivalenceSet::print(const std::string &prefix) const
+EquivalenceSet::print(const std::string& prefix) const
 {
   int i = 0;
-  for (auto it = equis.begin();
-       it != equis.end();
-       ++it, i++)
+  for (auto it = equis.begin(); it != equis.end(); ++it, i++)
     {
-      std::cout << prefix << "equivalence " << i << ":(classes "
-                << it->numClasses() << ")\n";
+      std::cout << prefix << "equivalence " << i << ":(classes " << it->numClasses() << ")\n";
       it->print(prefix + "    ");
     }
 }
@@ -395,12 +374,12 @@ EquivalenceBundle::EquivalenceBundle(int nmax)
 }
 
 /* Remember, that the first item is EquivalenceSet(1). */
-const EquivalenceSet &
+const EquivalenceSet&
 EquivalenceBundle::get(int n) const
 {
   TL_RAISE_IF(n > static_cast<int>(bundle.size()) || n < 1,
               "Equivalence set not found in EquivalenceBundle::get");
-  return bundle[n-1];
+  return bundle[n - 1];
 }
 
 /* Get ‘curmax’ which is a maximum size in the bundle, and generate for
@@ -410,6 +389,6 @@ void
 EquivalenceBundle::generateUpTo(int nmax)
 {
   int curmax = bundle.size();
-  for (int i = curmax+1; i <= nmax; i++)
+  for (int i = curmax + 1; i <= nmax; i++)
     bundle.emplace_back(i);
 }
diff --git a/mex/sources/libkorder/tl/equivalence.hh b/mex/sources/libkorder/tl/equivalence.hh
index b77c5400965ee859ff04ed5a68a2d85679b4ee3e..b73d745af1198450d3eea3a2342f0d87781a553d 100644
--- a/mex/sources/libkorder/tl/equivalence.hh
+++ b/mex/sources/libkorder/tl/equivalence.hh
@@ -55,9 +55,9 @@
 
 #include "int_sequence.hh"
 
-#include <vector>
 #include <list>
 #include <string>
+#include <vector>
 
 /* Here is the abstraction for an equivalence class. We implement it as
    vector<int>. We have a constructor for empty class, copy
@@ -69,14 +69,15 @@
 class OrdSequence
 {
   std::vector<int> data;
+
 public:
   OrdSequence() : data()
   {
   }
-  bool operator==(const OrdSequence &s) const;
+  bool operator==(const OrdSequence& s) const;
   int operator[](int i) const;
-  bool operator<(const OrdSequence &s) const;
-  const std::vector<int> &
+  bool operator<(const OrdSequence& s) const;
+  const std::vector<int>&
   getData() const
   {
     return data;
@@ -87,9 +88,10 @@ public:
     return data.size();
   }
   void add(int i);
-  void add(const OrdSequence &s);
+  void add(const OrdSequence& s);
   bool has(int i) const;
-  void print(const std::string &prefix) const;
+  void print(const std::string& prefix) const;
+
 private:
   double average() const;
 };
@@ -106,6 +108,7 @@ class Equivalence
 private:
   int n;
   std::list<OrdSequence> classes;
+
 public:
   using const_seqit = std::list<OrdSequence>::const_iterator;
   using seqit = std::list<OrdSequence>::iterator;
@@ -113,13 +116,13 @@ public:
   // Constructs { {0}, {1}, …, {n-1} }
   explicit Equivalence(int num);
   // Constructs { {0,1,…,n-1 } }
-  Equivalence(int num, const std::string &dummy);
+  Equivalence(int num, const std::string& dummy);
   // Copy constructor plus gluing i1 and i2 in one class
-  Equivalence(const Equivalence &e, int i1, int i2);
+  Equivalence(const Equivalence& e, int i1, int i2);
 
-  bool operator==(const Equivalence &e) const;
+  bool operator==(const Equivalence& e) const;
   bool
-  operator!=(const Equivalence &e) const
+  operator!=(const Equivalence& e) const
   {
     return !operator==(e);
   }
@@ -133,14 +136,14 @@ public:
   {
     return classes.size();
   }
-  void trace(IntSequence &out, int n) const;
+  void trace(IntSequence& out, int n) const;
   void
-  trace(IntSequence &out) const
+  trace(IntSequence& out) const
   {
     trace(out, numClasses());
   }
-  void trace(IntSequence &out, const Permutation &per) const;
-  void print(const std::string &prefix) const;
+  void trace(IntSequence& out, const Permutation& per) const;
+  void print(const std::string& prefix) const;
   seqit
   begin()
   {
@@ -163,6 +166,7 @@ public:
   }
   const_seqit find(int i) const;
   seqit find(int i);
+
 protected:
   /* Here we have find methods. We can find an equivalence class having a
      given number or we can find an equivalence class of a given index within
@@ -172,8 +176,7 @@ protected:
      according to the class ordering. */
   const_seqit findHaving(int i) const;
   seqit findHaving(int i);
-  void insert(const OrdSequence &s);
-
+  void insert(const OrdSequence& s);
 };
 
 /* The EquivalenceSet is a list of equivalences. The unique
@@ -187,9 +190,10 @@ class EquivalenceSet
 {
   int n;
   std::list<Equivalence> equis;
+
 public:
   explicit EquivalenceSet(int num);
-  void print(const std::string &prefix) const;
+  void print(const std::string& prefix) const;
   auto
   begin() const
   {
@@ -200,9 +204,10 @@ public:
   {
     return equis.end();
   }
+
 private:
-  bool has(const Equivalence &e) const;
-  void addParents(const Equivalence &e, std::list<Equivalence> &added);
+  bool has(const Equivalence& e) const;
+  void addParents(const Equivalence& e, std::list<Equivalence>& added);
 };
 
 /* The equivalence bundle class only encapsulates EquivalenceSet·s
@@ -215,9 +220,10 @@ private:
 class EquivalenceBundle
 {
   std::vector<EquivalenceSet> bundle;
+
 public:
   explicit EquivalenceBundle(int nmax);
-  const EquivalenceSet &get(int n) const;
+  const EquivalenceSet& get(int n) const;
   void generateUpTo(int nmax);
 };
 
diff --git a/mex/sources/libkorder/tl/fine_container.cc b/mex/sources/libkorder/tl/fine_container.cc
index c0e394dfd30869204c8d8fc23de81a00b59d6e51..83fdcb0b2dfdfb103dc866e566a5a7e09da5dba3 100644
--- a/mex/sources/libkorder/tl/fine_container.cc
+++ b/mex/sources/libkorder/tl/fine_container.cc
@@ -25,22 +25,22 @@
 /* Here we construct the vector of new sizes of containers (before
    nc) and copy all remaining sizes behind nc. */
 
-SizeRefinement::SizeRefinement(const IntSequence &s, int nc, int max)
+SizeRefinement::SizeRefinement(const IntSequence& s, int nc, int max)
 {
   new_nc = 0;
   for (int i = 0; i < nc; i++)
     {
-      int nr = s[i]/max;
+      int nr = s[i] / max;
       if (s[i] % max != 0)
         nr++;
-      int ss = (nr > 0) ? static_cast<int>(round(static_cast<double>(s[i])/nr)) : 0;
+      int ss = (nr > 0) ? static_cast<int>(round(static_cast<double>(s[i]) / nr)) : 0;
       for (int j = 0; j < nr - 1; j++)
         {
           rsizes.push_back(ss);
           ind_map.push_back(i);
           new_nc++;
         }
-      rsizes.push_back(s[i]-(nr-1)*ss);
+      rsizes.push_back(s[i] - (nr - 1) * ss);
       ind_map.push_back(i);
       new_nc++;
     }
diff --git a/mex/sources/libkorder/tl/fine_container.hh b/mex/sources/libkorder/tl/fine_container.hh
index 6996160f8ef0bfb09283adb91164156534ab7d08..6e57f5c02c28382f61bd4325719d0481d4df6ae9 100644
--- a/mex/sources/libkorder/tl/fine_container.hh
+++ b/mex/sources/libkorder/tl/fine_container.hh
@@ -47,8 +47,8 @@
 
 #include "stack_container.hh"
 
-#include <vector>
 #include <memory>
+#include <vector>
 
 /* This class splits the first nc elements of the given sequence s
    to a sequence not having items greater than given max. The remaining
@@ -61,8 +61,9 @@ class SizeRefinement
   std::vector<int> rsizes;
   std::vector<int> ind_map;
   int new_nc;
+
 public:
-  SizeRefinement(const IntSequence &s, int nc, int max);
+  SizeRefinement(const IntSequence& s, int nc, int max);
   int
   getRefSize(int i) const
   {
@@ -98,7 +99,8 @@ protected:
   using _Ctype = typename StackContainerInterface<_Ttype>::_Ctype;
   using itype = typename StackContainerInterface<_Ttype>::itype;
   std::vector<std::unique_ptr<_Ctype>> ref_conts;
-  const _Stype &stack_cont;
+  const _Stype& stack_cont;
+
 public:
   /* Here we construct the SizeRefinement and allocate space for the
      refined containers. Then, the containers are created and put to
@@ -114,11 +116,10 @@ public:
      StackContainer has only a const method to return a member of
      conts. */
 
-  FineContainer(const _Stype &sc, int max)
-    : SizeRefinement(sc.getStackSizes(), sc.numConts(), max),
-      StackContainer<_Ttype>(numRefinements(), getNC()),
-      ref_conts(getNC()),
-      stack_cont(sc)
+  FineContainer(const _Stype& sc, int max) :
+      SizeRefinement(sc.getStackSizes(), sc.numConts(), max), StackContainer<_Ttype>(
+                                                                  numRefinements(), getNC()),
+      ref_conts(getNC()), stack_cont(sc)
   {
     for (int i = 0; i < numRefinements(); i++)
       _Stype::stack_sizes[i] = getRefSize(i);
@@ -134,26 +135,25 @@ public:
             last_row = 0;
           }
         ref_conts[i] = std::make_unique<_Ctype>(last_row, _Stype::stack_sizes[i],
-                                                const_cast<_Ctype &>(stack_cont.getCont(last_cont)));
+                                                const_cast<_Ctype&>(stack_cont.getCont(last_cont)));
         _Stype::conts[i] = ref_conts[i].get();
         last_row += _Stype::stack_sizes[i];
       }
   }
 
   itype
-  getType(int i, const Symmetry &s) const override
+  getType(int i, const Symmetry& s) const override
   {
     return stack_cont.getType(getOldIndex(i), s);
   }
-
 };
 
 /* Here is FineContainer specialization for folded tensors. */
 class FoldedFineContainer : public FineContainer<FGSTensor>, public FoldedStackContainer
 {
 public:
-  FoldedFineContainer(const StackContainer<FGSTensor> &sc, int max)
-    : FineContainer<FGSTensor>(sc, max)
+  FoldedFineContainer(const StackContainer<FGSTensor>& sc, int max) :
+      FineContainer<FGSTensor>(sc, max)
   {
   }
 };
@@ -162,8 +162,8 @@ public:
 class UnfoldedFineContainer : public FineContainer<UGSTensor>, public UnfoldedStackContainer
 {
 public:
-  UnfoldedFineContainer(const StackContainer<UGSTensor> &sc, int max)
-    : FineContainer<UGSTensor>(sc, max)
+  UnfoldedFineContainer(const StackContainer<UGSTensor>& sc, int max) :
+      FineContainer<UGSTensor>(sc, max)
   {
   }
 };
diff --git a/mex/sources/libkorder/tl/fs_tensor.cc b/mex/sources/libkorder/tl/fs_tensor.cc
index 6b78f81d1fe3fbbf355abb90286ab295cb8d66b3..daf67d3b79506439b23fadd1d7c7c14de04a364c 100644
--- a/mex/sources/libkorder/tl/fs_tensor.cc
+++ b/mex/sources/libkorder/tl/fs_tensor.cc
@@ -20,10 +20,10 @@
 
 #include "fs_tensor.hh"
 #include "gs_tensor.hh"
-#include "sparse_tensor.hh"
+#include "pascal_triangle.hh"
 #include "rfs_tensor.hh"
+#include "sparse_tensor.hh"
 #include "tl_exception.hh"
-#include "pascal_triangle.hh"
 
 /* This constructs a fully symmetric tensor as given by the contraction:
 
@@ -34,13 +34,12 @@
    coordinates obtaining a column of tensor [t]. The column is multiplied
    by an appropriate item of x and added to the column of [g] tensor. */
 
-FFSTensor::FFSTensor(const FFSTensor &t, const ConstVector &x)
-  : FTensor(indor::along_col, IntSequence(t.dimen()-1, t.nvar()),
-            t.nrows(), calcMaxOffset(t.nvar(), t.dimen()-1), t.dimen()-1),
+FFSTensor::FFSTensor(const FFSTensor& t, const ConstVector& x) :
+    FTensor(indor::along_col, IntSequence(t.dimen() - 1, t.nvar()), t.nrows(),
+            calcMaxOffset(t.nvar(), t.dimen() - 1), t.dimen() - 1),
     nv(t.nvar())
 {
-  TL_RAISE_IF(t.dimen() < 1,
-              "Wrong dimension for tensor contraction of FFSTensor");
+  TL_RAISE_IF(t.dimen() < 1, "Wrong dimension for tensor contraction of FFSTensor");
   TL_RAISE_IF(t.nvar() != x.length(),
               "Wrong number of variables for tensor contraction of FFSTensor");
 
@@ -73,13 +72,13 @@ FFSTensor::calcMaxOffset(int nvar, int d)
 
 /* The conversion from sparse tensor is clear. We go through all the
    tensor and write to the dense what is found. */
-FFSTensor::FFSTensor(const FSSparseTensor &t)
-  : FTensor(indor::along_col, IntSequence(t.dimen(), t.nvar()),
-            t.nrows(), calcMaxOffset(t.nvar(), t.dimen()), t.dimen()),
+FFSTensor::FFSTensor(const FSSparseTensor& t) :
+    FTensor(indor::along_col, IntSequence(t.dimen(), t.nvar()), t.nrows(),
+            calcMaxOffset(t.nvar(), t.dimen()), t.dimen()),
     nv(t.nvar())
 {
   zeros();
-  for (const auto &it : t.getMap())
+  for (const auto& it : t.getMap())
     {
       index ind(*this, it.first);
       get(it.second.first, *ind) = it.second.second;
@@ -91,9 +90,9 @@ FFSTensor::FFSTensor(const FSSparseTensor &t)
    (this), make an index of the unfolded vector from coordinates, and
    copy the column. */
 
-FFSTensor::FFSTensor(const UFSTensor &ut)
-  : FTensor(indor::along_col, IntSequence(ut.dimen(), ut.nvar()),
-            ut.nrows(), calcMaxOffset(ut.nvar(), ut.dimen()), ut.dimen()),
+FFSTensor::FFSTensor(const UFSTensor& ut) :
+    FTensor(indor::along_col, IntSequence(ut.dimen(), ut.nvar()), ut.nrows(),
+            calcMaxOffset(ut.nvar(), ut.dimen()), ut.dimen()),
     nv(ut.nvar())
 {
   for (index in = begin(); in != end(); ++in)
@@ -116,10 +115,9 @@ FFSTensor::unfold() const
    which corresponds to monotonizeing the integer sequence. */
 
 void
-FFSTensor::increment(IntSequence &v) const
+FFSTensor::increment(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input/output vector size in FFSTensor::increment");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input/output vector size in FFSTensor::increment");
 
   UTensor::increment(v, nv);
   v.monotone();
@@ -128,19 +126,17 @@ FFSTensor::increment(IntSequence &v) const
 /* Decrement calls static FTensor::decrement(). */
 
 void
-FFSTensor::decrement(IntSequence &v) const
+FFSTensor::decrement(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input/output vector size in FFSTensor::decrement");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input/output vector size in FFSTensor::decrement");
 
   FTensor::decrement(v, nv);
 }
 
 int
-FFSTensor::getOffset(const IntSequence &v) const
+FFSTensor::getOffset(const IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input vector size in FFSTensor::getOffset");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input vector size in FFSTensor::getOffset");
 
   return FTensor::getOffset(v, nv);
 }
@@ -156,18 +152,16 @@ FFSTensor::getOffset(const IntSequence &v) const
    through the columns in general symmetry, adding the shift and sorting. */
 
 void
-FFSTensor::addSubTensor(const FGSTensor &t)
+FFSTensor::addSubTensor(const FGSTensor& t)
 {
-  TL_RAISE_IF(dimen() != t.getDims().dimen(),
-              "Wrong dimensions for FFSTensor::addSubTensor");
-  TL_RAISE_IF(nvar() != t.getDims().getNVS().sum(),
-              "Wrong nvs for FFSTensor::addSubTensor");
+  TL_RAISE_IF(dimen() != t.getDims().dimen(), "Wrong dimensions for FFSTensor::addSubTensor");
+  TL_RAISE_IF(nvar() != t.getDims().getNVS().sum(), "Wrong nvs for FFSTensor::addSubTensor");
 
   // set shift for addSubTensor()
   /* Code shared with UFSTensor::addSubTensor() */
   IntSequence shift_pre(t.getSym().num(), 0);
   for (int i = 1; i < t.getSym().num(); i++)
-    shift_pre[i] = shift_pre[i-1]+t.getDims().getNVS()[i-1];
+    shift_pre[i] = shift_pre[i - 1] + t.getDims().getNVS()[i - 1];
   IntSequence shift(shift_pre.unfold(t.getSym()));
 
   for (Tensor::index ind = t.begin(); ind != t.end(); ++ind)
@@ -185,13 +179,12 @@ FFSTensor::addSubTensor(const FGSTensor &t)
    We do not add column by column but we do it by submatrices due to
    regularity of the unfolded tensor. */
 
-UFSTensor::UFSTensor(const UFSTensor &t, const ConstVector &x)
-  : UTensor(indor::along_col, IntSequence(t.dimen()-1, t.nvar()),
-            t.nrows(), calcMaxOffset(t.nvar(), t.dimen()-1), t.dimen()-1),
+UFSTensor::UFSTensor(const UFSTensor& t, const ConstVector& x) :
+    UTensor(indor::along_col, IntSequence(t.dimen() - 1, t.nvar()), t.nrows(),
+            calcMaxOffset(t.nvar(), t.dimen() - 1), t.dimen() - 1),
     nv(t.nvar())
 {
-  TL_RAISE_IF(t.dimen() < 1,
-              "Wrong dimension for tensor contraction of UFSTensor");
+  TL_RAISE_IF(t.dimen() < 1, "Wrong dimension for tensor contraction of UFSTensor");
   TL_RAISE_IF(t.nvar() != x.length(),
               "Wrong number of variables for tensor contraction of UFSTensor");
 
@@ -199,8 +192,8 @@ UFSTensor::UFSTensor(const UFSTensor &t, const ConstVector &x)
 
   for (int i = 0; i < ncols(); i++)
     {
-      ConstTwoDMatrix tpart(t, i *nvar(), nvar());
-      Vector outcol{getCol(i)};
+      ConstTwoDMatrix tpart(t, i * nvar(), nvar());
+      Vector outcol {getCol(i)};
       tpart.multaVec(outcol, x);
     }
 }
@@ -208,9 +201,9 @@ UFSTensor::UFSTensor(const UFSTensor &t, const ConstVector &x)
 /* Here we convert folded full symmetry tensor to unfolded. We copy all
    columns of folded tensor, and then call unfoldData(). */
 
-UFSTensor::UFSTensor(const FFSTensor &ft)
-  : UTensor(indor::along_col, IntSequence(ft.dimen(), ft.nvar()),
-            ft.nrows(), calcMaxOffset(ft.nvar(), ft.dimen()), ft.dimen()),
+UFSTensor::UFSTensor(const FFSTensor& ft) :
+    UTensor(indor::along_col, IntSequence(ft.dimen(), ft.nvar()), ft.nrows(),
+            calcMaxOffset(ft.nvar(), ft.dimen()), ft.dimen()),
     nv(ft.nvar())
 {
   for (index src = ft.begin(); src != ft.end(); ++src)
@@ -230,28 +223,25 @@ UFSTensor::fold() const
 // UFSTensor increment and decrement
 /* Here we just call UTensor respective static methods. */
 void
-UFSTensor::increment(IntSequence &v) const
+UFSTensor::increment(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input/output vector size in UFSTensor::increment");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input/output vector size in UFSTensor::increment");
 
   UTensor::increment(v, nv);
 }
 
 void
-UFSTensor::decrement(IntSequence &v) const
+UFSTensor::decrement(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input/output vector size in UFSTensor::decrement");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input/output vector size in UFSTensor::decrement");
 
   UTensor::decrement(v, nv);
 }
 
 int
-UFSTensor::getOffset(const IntSequence &v) const
+UFSTensor::getOffset(const IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input vector size in UFSTensor::getOffset");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input vector size in UFSTensor::getOffset");
 
   return UTensor::getOffset(v, nv);
 }
@@ -263,18 +253,16 @@ UFSTensor::getOffset(const IntSequence &v) const
    tensor, and add it. */
 
 void
-UFSTensor::addSubTensor(const UGSTensor &t)
+UFSTensor::addSubTensor(const UGSTensor& t)
 {
-  TL_RAISE_IF(dimen() != t.getDims().dimen(),
-              "Wrong dimensions for UFSTensor::addSubTensor");
-  TL_RAISE_IF(nvar() != t.getDims().getNVS().sum(),
-              "Wrong nvs for UFSTensor::addSubTensor");
+  TL_RAISE_IF(dimen() != t.getDims().dimen(), "Wrong dimensions for UFSTensor::addSubTensor");
+  TL_RAISE_IF(nvar() != t.getDims().getNVS().sum(), "Wrong nvs for UFSTensor::addSubTensor");
 
   // set shift for addSubTensor()
   /* Code shared with FFSTensor::addSubTensor() */
   IntSequence shift_pre(t.getSym().num(), 0);
   for (int i = 1; i < t.getSym().num(); i++)
-    shift_pre[i] = shift_pre[i-1]+t.getDims().getNVS()[i-1];
+    shift_pre[i] = shift_pre[i - 1] + t.getDims().getNVS()[i - 1];
   IntSequence shift(shift_pre.unfold(t.getSym()));
 
   for (Tensor::index tar = begin(); tar != end(); ++tar)
diff --git a/mex/sources/libkorder/tl/fs_tensor.hh b/mex/sources/libkorder/tl/fs_tensor.hh
index 25c70793c04d80715dda2fe5de2bf1853d21da93..dd84a89df92b848440f5a1f6990c2041e4ce754a 100644
--- a/mex/sources/libkorder/tl/fs_tensor.hh
+++ b/mex/sources/libkorder/tl/fs_tensor.hh
@@ -27,9 +27,9 @@
 #ifndef FS_TENSOR_H
 #define FS_TENSOR_H
 
-#include "tensor.hh"
-#include "symmetry.hh"
 #include "int_power.hh"
+#include "symmetry.hh"
+#include "tensor.hh"
 
 class FGSTensor;
 class UGSTensor;
@@ -59,14 +59,13 @@ class UFSTensor;
 class FFSTensor : public FTensor
 {
   int nv;
+
 public:
   /* Constructs given the number of rows (explicit since the tensor is
      column-oriented), the number of variables in each dimension, and the
      number of dimensions */
-  FFSTensor(int r, int nvar, int d)
-    : FTensor(indor::along_col, IntSequence(d, nvar),
-              r, calcMaxOffset(nvar, d), d),
-      nv(nvar)
+  FFSTensor(int r, int nvar, int d) :
+      FTensor(indor::along_col, IntSequence(d, nvar), r, calcMaxOffset(nvar, d), d), nv(nvar)
   {
   }
 
@@ -76,35 +75,34 @@ public:
      [g_yⁿ]_α₁…αₙ = [t_yⁿ⁺¹]_α₁…αₙβ [x]^β
 
      See the implementation for details. */
-  FFSTensor(const FFSTensor &t, const ConstVector &x);
+  FFSTensor(const FFSTensor& t, const ConstVector& x);
 
   /* Converts from sparse tensor (which is fully symmetric and folded by
      nature). */
-  explicit FFSTensor(const FSSparseTensor &t);
+  explicit FFSTensor(const FSSparseTensor& t);
 
-  FFSTensor(const FFSTensor &) = default;
-  FFSTensor(FFSTensor &&) = default;
+  FFSTensor(const FFSTensor&) = default;
+  FFSTensor(FFSTensor&&) = default;
 
   // Constructs from unfolded fully symmetric
-  explicit FFSTensor(const UFSTensor &ut);
+  explicit FFSTensor(const UFSTensor& ut);
 
   // Constructs a subtensor of selected rows
-  FFSTensor(int first_row, int num, FFSTensor &t)
-    : FTensor(first_row, num, t), nv(t.nv)
+  FFSTensor(int first_row, int num, FFSTensor& t) : FTensor(first_row, num, t), nv(t.nv)
   {
   }
 
-  void increment(IntSequence &v) const override;
-  void decrement(IntSequence &v) const override;
+  void increment(IntSequence& v) const override;
+  void decrement(IntSequence& v) const override;
   std::unique_ptr<UTensor> unfold() const override;
   Symmetry
   getSym() const
   {
-    return Symmetry{dimen()};
+    return Symmetry {dimen()};
   }
 
-  int getOffset(const IntSequence &v) const override;
-  void addSubTensor(const FGSTensor &t);
+  int getOffset(const IntSequence& v) const override;
+  void addSubTensor(const FGSTensor& t);
   int
   nvar() const
   {
@@ -122,33 +120,31 @@ public:
 class UFSTensor : public UTensor
 {
   int nv;
+
 public:
-  UFSTensor(int r, int nvar, int d)
-    : UTensor(indor::along_col, IntSequence(d, nvar),
-              r, calcMaxOffset(nvar, d), d),
-      nv(nvar)
+  UFSTensor(int r, int nvar, int d) :
+      UTensor(indor::along_col, IntSequence(d, nvar), r, calcMaxOffset(nvar, d), d), nv(nvar)
   {
   }
-  UFSTensor(const UFSTensor &t, const ConstVector &x);
-  UFSTensor(const UFSTensor &) = default;
-  UFSTensor(UFSTensor &&) = default;
-  explicit UFSTensor(const FFSTensor &ft);
-  UFSTensor(int first_row, int num, UFSTensor &t)
-    : UTensor(first_row, num, t), nv(t.nv)
+  UFSTensor(const UFSTensor& t, const ConstVector& x);
+  UFSTensor(const UFSTensor&) = default;
+  UFSTensor(UFSTensor&&) = default;
+  explicit UFSTensor(const FFSTensor& ft);
+  UFSTensor(int first_row, int num, UFSTensor& t) : UTensor(first_row, num, t), nv(t.nv)
   {
   }
 
-  void increment(IntSequence &v) const override;
-  void decrement(IntSequence &v) const override;
+  void increment(IntSequence& v) const override;
+  void decrement(IntSequence& v) const override;
   std::unique_ptr<FTensor> fold() const override;
   Symmetry
   getSym() const
   {
-    return Symmetry{dimen()};
+    return Symmetry {dimen()};
   }
 
-  int getOffset(const IntSequence &v) const override;
-  void addSubTensor(const UGSTensor &t);
+  int getOffset(const IntSequence& v) const override;
+  void addSubTensor(const UGSTensor& t);
   int
   nvar() const
   {
@@ -159,6 +155,7 @@ public:
   {
     return power(nvar, d);
   }
+
 private:
   void unfoldData();
 };
diff --git a/mex/sources/libkorder/tl/gs_tensor.cc b/mex/sources/libkorder/tl/gs_tensor.cc
index bf32dfb4e9257ae8e1657b6aadd3c825051bc6ea..637dcaa9332a5472d156ed51ac2aa16783e409a9 100644
--- a/mex/sources/libkorder/tl/gs_tensor.cc
+++ b/mex/sources/libkorder/tl/gs_tensor.cc
@@ -19,10 +19,10 @@
  */
 
 #include "gs_tensor.hh"
-#include "sparse_tensor.hh"
-#include "tl_exception.hh"
 #include "kron_prod.hh"
 #include "pascal_triangle.hh"
+#include "sparse_tensor.hh"
+#include "tl_exception.hh"
 
 /* Constructor used for slicing fully symmetric tensor. It constructs the
    dimensions from the partitioning of variables of fully symmetric tensor. Let
@@ -35,14 +35,11 @@
    sizes of partitions (n_a,n_b,n_c,n_d) as IntSequence, and indices of
    picked partitions, in our case (1,1,3,3,3), as IntSequence. */
 
-TensorDimens::TensorDimens(const IntSequence &ss, const IntSequence &coor)
-  : nvs(ss),
-    sym(ss.size()),
-    nvmax(coor.size(), 0)
+TensorDimens::TensorDimens(const IntSequence& ss, const IntSequence& coor) :
+    nvs(ss), sym(ss.size()), nvmax(coor.size(), 0)
 {
-  TL_RAISE_IF(!coor.isSorted(),
-              "Coordinates not sorted in TensorDimens slicing constructor");
-  TL_RAISE_IF(coor[0] < 0 || coor[coor.size()-1] >= ss.size(),
+  TL_RAISE_IF(!coor.isSorted(), "Coordinates not sorted in TensorDimens slicing constructor");
+  TL_RAISE_IF(coor[0] < 0 || coor[coor.size() - 1] >= ss.size(),
               "A coordinate out of stack range in TensorDimens slicing constructor");
 
   for (int i = 0; i < coor.size(); i++)
@@ -71,7 +68,7 @@ TensorDimens::calcFoldMaxOffset() const
       if (nvs[i] == 0 && sym[i] > 0)
         return 0;
       if (sym[i] > 0)
-        res *= PascalTriangle::noverk(nvs[i]+sym[i]-1, sym[i]);
+        res *= PascalTriangle::noverk(nvs[i] + sym[i] - 1, sym[i]);
     }
   return res;
 }
@@ -97,26 +94,23 @@ TensorDimens::calcFoldMaxOffset() const
    product in ‘pow’. */
 
 int
-TensorDimens::calcFoldOffset(const IntSequence &v) const
+TensorDimens::calcFoldOffset(const IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input vector size in TensorDimens::getFoldOffset");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input vector size in TensorDimens::getFoldOffset");
 
   int res = 0;
   int pow = 1;
   int blstart = v.size();
-  for (int ibl = getSym().num()-1; ibl >= 0; ibl--)
-    if (int bldim { getSym()[ibl] };
-        bldim > 0)
+  for (int ibl = getSym().num() - 1; ibl >= 0; ibl--)
+    if (int bldim {getSym()[ibl]}; bldim > 0)
       {
         blstart -= bldim;
         int blnvar = getNVX(blstart);
-        IntSequence subv(v, blstart, blstart+bldim);
-        res += FTensor::getOffset(subv, blnvar)*pow;
+        IntSequence subv(v, blstart, blstart + bldim);
+        res += FTensor::getOffset(subv, blnvar) * pow;
         pow *= FFSTensor::calcMaxOffset(blnvar, bldim);
       }
-  TL_RAISE_IF(blstart != 0,
-              "Error in tracing symmetry in TensorDimens::getFoldOffset");
+  TL_RAISE_IF(blstart != 0, "Error in tracing symmetry in TensorDimens::getFoldOffset");
   return res;
 }
 
@@ -138,17 +132,17 @@ TensorDimens::calcFoldOffset(const IntSequence &v) const
    index (fully symmetric within that partition). */
 
 void
-TensorDimens::decrement(IntSequence &v) const
+TensorDimens::decrement(IntSequence& v) const
 {
   TL_RAISE_IF(getNVX().size() != v.size(),
               "Wrong size of input/output sequence in TensorDimens::decrement");
 
-  int iblock = getSym().num()-1;
+  int iblock = getSym().num() - 1;
   int block_last = v.size();
-  int block_first = block_last-getSym()[iblock];
+  int block_first = block_last - getSym()[iblock];
 
   // check for zero trailing blocks
-  while (iblock > 0 && v[block_last-1] == 0)
+  while (iblock > 0 && v[block_last - 1] == 0)
     {
       for (int i = block_first; i < block_last; i++)
         v[i] = getNVX(i); // equivalent to nvs[iblock]
@@ -165,9 +159,9 @@ TensorDimens::decrement(IntSequence &v) const
 // FGSTensor conversion from UGSTensor
 /* Here we go through columns of folded, calculate column of unfolded,
    and copy data. */
-FGSTensor::FGSTensor(const UGSTensor &ut)
-  : FTensor(indor::along_col, ut.tdims.getNVX(), ut.nrows(),
-            ut.tdims.calcFoldMaxOffset(), ut.dimen()),
+FGSTensor::FGSTensor(const UGSTensor& ut) :
+    FTensor(indor::along_col, ut.tdims.getNVX(), ut.nrows(), ut.tdims.calcFoldMaxOffset(),
+            ut.dimen()),
     tdims(ut.tdims)
 {
   for (index ti = begin(); ti != end(); ++ti)
@@ -186,10 +180,9 @@ FGSTensor::FGSTensor(const UGSTensor &ut)
    in Cartesian ordering (this corresponds to belonging to the
    slices). If it belongs, then we subtract the lower bound ‘lb’ to
    obtain coordinates in the ‘this’ tensor and we copy the item. */
-FGSTensor::FGSTensor(const FSSparseTensor &t, const IntSequence &ss,
-                     const IntSequence &coor, TensorDimens td)
-  : FTensor(indor::along_col, td.getNVX(), t.nrows(),
-            td.calcFoldMaxOffset(), td.dimen()),
+FGSTensor::FGSTensor(const FSSparseTensor& t, const IntSequence& ss, const IntSequence& coor,
+                     TensorDimens td) :
+    FTensor(indor::along_col, td.getNVX(), t.nrows(), td.calcFoldMaxOffset(), td.dimen()),
     tdims(std::move(td))
 {
   // set ‘lb’ and ‘ub’ to lower and upper bounds of indices
@@ -201,7 +194,7 @@ FGSTensor::FGSTensor(const FSSparseTensor &t, const IntSequence &ss,
      slice. */
   IntSequence s_offsets(ss.size(), 0);
   for (int i = 1; i < ss.size(); i++)
-    s_offsets[i] = s_offsets[i-1] + ss[i-1];
+    s_offsets[i] = s_offsets[i - 1] + ss[i - 1];
 
   IntSequence lb(coor.size());
   IntSequence ub(coor.size());
@@ -228,10 +221,9 @@ FGSTensor::FGSTensor(const FSSparseTensor &t, const IntSequence &ss,
 
 // FGSTensor slicing from FFSTensor
 /* The code is similar to FGSTensor slicing from FSSparseTensor. */
-FGSTensor::FGSTensor(const FFSTensor &t, const IntSequence &ss,
-                     const IntSequence &coor, TensorDimens td)
-  : FTensor(indor::along_col, td.getNVX(), t.nrows(),
-            td.calcFoldMaxOffset(), td.dimen()),
+FGSTensor::FGSTensor(const FFSTensor& t, const IntSequence& ss, const IntSequence& coor,
+                     TensorDimens td) :
+    FTensor(indor::along_col, td.getNVX(), t.nrows(), td.calcFoldMaxOffset(), td.dimen()),
     tdims(std::move(td))
 {
   if (ncols() == 0)
@@ -241,7 +233,7 @@ FGSTensor::FGSTensor(const FFSTensor &t, const IntSequence &ss,
   /* Same code as in the previous converting constructor */
   IntSequence s_offsets(ss.size(), 0);
   for (int i = 1; i < ss.size(); i++)
-    s_offsets[i] = s_offsets[i-1] + ss[i-1];
+    s_offsets[i] = s_offsets[i - 1] + ss[i - 1];
 
   IntSequence lb(coor.size());
   IntSequence ub(coor.size());
@@ -268,12 +260,13 @@ FGSTensor::FGSTensor(const FFSTensor &t, const IntSequence &ss,
 }
 
 // FGSTensor conversion from GSSparseTensor
-FGSTensor::FGSTensor(const GSSparseTensor &t)
-  : FTensor(indor::along_col, t.getDims().getNVX(), t.nrows(),
-            t.getDims().calcFoldMaxOffset(), t.dimen()), tdims(t.getDims())
+FGSTensor::FGSTensor(const GSSparseTensor& t) :
+    FTensor(indor::along_col, t.getDims().getNVX(), t.nrows(), t.getDims().calcFoldMaxOffset(),
+            t.dimen()),
+    tdims(t.getDims())
 {
   zeros();
-  for (const auto &it : t.getMap())
+  for (const auto& it : t.getMap())
     {
       index ind(*this, it.first);
       get(it.second.first, *ind) = it.second.second;
@@ -285,10 +278,9 @@ FGSTensor::FGSTensor(const GSSparseTensor &t)
    IntSequence::pmonotone(). */
 
 void
-FGSTensor::increment(IntSequence &v) const
+FGSTensor::increment(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input/output vector size in FGSTensor::increment");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input/output vector size in FGSTensor::increment");
 
   UTensor::increment(v, tdims.getNVX());
   v.pmonotone(tdims.getSym());
@@ -322,11 +314,9 @@ FGSTensor::unfold() const
    starting from 0. */
 
 void
-FGSTensor::contractAndAdd(int i, FGSTensor &out,
-                          const FRSingleTensor &col) const
+FGSTensor::contractAndAdd(int i, FGSTensor& out, const FRSingleTensor& col) const
 {
-  TL_RAISE_IF(i < 0 || i >= getSym().num(),
-              "Wrong index for FGSTensor::contractAndAdd");
+  TL_RAISE_IF(i < 0 || i >= getSym().num(), "Wrong index for FGSTensor::contractAndAdd");
 
   TL_RAISE_IF(getSym()[i] != col.dimen() || tdims.getNVS()[i] != col.nvar(),
               "Wrong dimensions for FGSTensor::contractAndAdd");
@@ -362,9 +352,9 @@ FGSTensor::contractAndAdd(int i, FGSTensor &out,
    of the unfolded tensor and copy the data to the unfolded. Then we
    unfold data within the unfolded tensor. */
 
-UGSTensor::UGSTensor(const FGSTensor &ft)
-  : UTensor(indor::along_col, ft.tdims.getNVX(), ft.nrows(),
-            ft.tdims.calcUnfoldMaxOffset(), ft.dimen()),
+UGSTensor::UGSTensor(const FGSTensor& ft) :
+    UTensor(indor::along_col, ft.tdims.getNVX(), ft.nrows(), ft.tdims.calcUnfoldMaxOffset(),
+            ft.dimen()),
     tdims(ft.tdims)
 {
   for (index fi = ft.begin(); fi != ft.end(); ++fi)
@@ -377,10 +367,9 @@ UGSTensor::UGSTensor(const FGSTensor &ft)
 
 // UGSTensor slicing from FSSparseTensor
 /* This makes a folded slice from the sparse tensor and unfolds it. */
-UGSTensor::UGSTensor(const FSSparseTensor &t, const IntSequence &ss,
-                     const IntSequence &coor, TensorDimens td)
-  : UTensor(indor::along_col, td.getNVX(), t.nrows(),
-            td.calcUnfoldMaxOffset(), td.dimen()),
+UGSTensor::UGSTensor(const FSSparseTensor& t, const IntSequence& ss, const IntSequence& coor,
+                     TensorDimens td) :
+    UTensor(indor::along_col, td.getNVX(), t.nrows(), td.calcUnfoldMaxOffset(), td.dimen()),
     tdims(std::move(td))
 {
   if (ncols() == 0)
@@ -397,10 +386,9 @@ UGSTensor::UGSTensor(const FSSparseTensor &t, const IntSequence &ss,
 
 // UGSTensor slicing from UFSTensor
 /* This makes a folded slice from dense and unfolds it. */
-UGSTensor::UGSTensor(const UFSTensor &t, const IntSequence &ss,
-                     const IntSequence &coor, TensorDimens td)
-  : UTensor(indor::along_col, td.getNVX(), t.nrows(),
-            td.calcUnfoldMaxOffset(), td.dimen()),
+UGSTensor::UGSTensor(const UFSTensor& t, const IntSequence& ss, const IntSequence& coor,
+                     TensorDimens td) :
+    UTensor(indor::along_col, td.getNVX(), t.nrows(), td.calcUnfoldMaxOffset(), td.dimen()),
     tdims(std::move(td))
 {
   FFSTensor folded(t);
@@ -416,19 +404,17 @@ UGSTensor::UGSTensor(const UFSTensor &t, const IntSequence &ss,
 // UGSTensor increment and decrement codes
 /* Clear, just call UTensor static methods. */
 void
-UGSTensor::increment(IntSequence &v) const
+UGSTensor::increment(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input/output vector size in UGSTensor::increment");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input/output vector size in UGSTensor::increment");
 
   UTensor::increment(v, tdims.getNVX());
 }
 
 void
-UGSTensor::decrement(IntSequence &v) const
+UGSTensor::decrement(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input/output vector size in UGSTensor::decrement");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input/output vector size in UGSTensor::decrement");
 
   UTensor::decrement(v, tdims.getNVX());
 }
@@ -442,10 +428,9 @@ UGSTensor::fold() const
 
 /* Return an offset of a given index. */
 int
-UGSTensor::getOffset(const IntSequence &v) const
+UGSTensor::getOffset(const IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input vector size in UGSTensor::getOffset");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input vector size in UGSTensor::getOffset");
 
   return UTensor::getOffset(v, tdims.getNVX());
 }
@@ -465,13 +450,13 @@ UGSTensor::unfoldData()
    partitions of the index. */
 
 Tensor::index
-UGSTensor::getFirstIndexOf(const index &in) const
+UGSTensor::getFirstIndexOf(const index& in) const
 {
   IntSequence v(in.getCoor());
   int last = 0;
   for (int i = 0; i < tdims.getSym().num(); i++)
     {
-      IntSequence vtmp(v, last, last+tdims.getSym()[i]);
+      IntSequence vtmp(v, last, last + tdims.getSym()[i]);
       vtmp.sort();
       last += tdims.getSym()[i];
     }
@@ -482,11 +467,9 @@ UGSTensor::getFirstIndexOf(const index &in) const
    FGSTensor::contractAndAdd(). */
 
 void
-UGSTensor::contractAndAdd(int i, UGSTensor &out,
-                          const URSingleTensor &col) const
+UGSTensor::contractAndAdd(int i, UGSTensor& out, const URSingleTensor& col) const
 {
-  TL_RAISE_IF(i < 0 || i >= getSym().num(),
-              "Wrong index for UGSTensor::contractAndAdd");
+  TL_RAISE_IF(i < 0 || i >= getSym().num(), "Wrong index for UGSTensor::contractAndAdd");
   TL_RAISE_IF(getSym()[i] != col.dimen() || tdims.getNVS()[i] != col.nvar(),
               "Wrong dimensions for UGSTensor::contractAndAdd");
 
diff --git a/mex/sources/libkorder/tl/gs_tensor.hh b/mex/sources/libkorder/tl/gs_tensor.hh
index d198d45489e34313b695e561f23354685a33cfbd..324d5b4d955409b9ce7332f5acde090604867f60 100644
--- a/mex/sources/libkorder/tl/gs_tensor.hh
+++ b/mex/sources/libkorder/tl/gs_tensor.hh
@@ -37,10 +37,10 @@
 #ifndef GS_TENSOR_H
 #define GS_TENSOR_H
 
-#include "tensor.hh"
 #include "fs_tensor.hh"
-#include "symmetry.hh"
 #include "rfs_tensor.hh"
+#include "symmetry.hh"
+#include "tensor.hh"
 
 class FGSTensor;
 class UGSTensor;
@@ -63,26 +63,26 @@ protected:
   IntSequence nvs;
   Symmetry sym;
   IntSequence nvmax;
+
 public:
-  TensorDimens(Symmetry s, IntSequence nvars)
-    : nvs(std::move(nvars)), sym(std::move(s)), nvmax(nvs.unfold(sym))
+  TensorDimens(Symmetry s, IntSequence nvars) :
+      nvs(std::move(nvars)), sym(std::move(s)), nvmax(nvs.unfold(sym))
   {
   }
   // Full-symmetry special case
-  TensorDimens(int nvar, int dimen)
-    : nvs{nvar}, sym{dimen}, nvmax(dimen, nvar)
+  TensorDimens(int nvar, int dimen) : nvs {nvar}, sym {dimen}, nvmax(dimen, nvar)
   {
   }
   // Constructs the tensor dimensions for slicing (see the implementation for details)
-  TensorDimens(const IntSequence &ss, const IntSequence &coor);
+  TensorDimens(const IntSequence& ss, const IntSequence& coor);
 
   bool
-  operator==(const TensorDimens &td) const
+  operator==(const TensorDimens& td) const
   {
     return nvs == td.nvs && sym == td.sym;
   }
   bool
-  operator!=(const TensorDimens &td) const
+  operator!=(const TensorDimens& td) const
   {
     return !operator==(td);
   }
@@ -97,17 +97,17 @@ public:
   {
     return nvmax[i];
   }
-  const IntSequence &
+  const IntSequence&
   getNVS() const
   {
     return nvs;
   }
-  const IntSequence &
+  const IntSequence&
   getNVX() const
   {
     return nvmax;
   }
-  const Symmetry &
+  const Symmetry&
   getSym() const
   {
     return sym;
@@ -115,8 +115,8 @@ public:
 
   int calcUnfoldMaxOffset() const;
   int calcFoldMaxOffset() const;
-  int calcFoldOffset(const IntSequence &v) const;
-  void decrement(IntSequence &v) const;
+  int calcFoldOffset(const IntSequence& v) const;
+  void decrement(IntSequence& v) const;
 };
 
 /* Here is a class for folded general symmetry tensor. It only contains
@@ -129,51 +129,49 @@ class FGSTensor : public FTensor
   friend class UGSTensor;
 
   const TensorDimens tdims;
+
 public:
-  FGSTensor(int r, TensorDimens td)
-    : FTensor(indor::along_col, td.getNVX(), r,
-              td.calcFoldMaxOffset(), td.dimen()), tdims(std::move(td))
+  FGSTensor(int r, TensorDimens td) :
+      FTensor(indor::along_col, td.getNVX(), r, td.calcFoldMaxOffset(), td.dimen()),
+      tdims(std::move(td))
   {
   }
-  FGSTensor(const FGSTensor &) = default;
-  FGSTensor(FGSTensor &&) = default;
+  FGSTensor(const FGSTensor&) = default;
+  FGSTensor(FGSTensor&&) = default;
 
-  FGSTensor(int first_row, int num, FGSTensor &t)
-    : FTensor(first_row, num, t), tdims(t.tdims)
+  FGSTensor(int first_row, int num, FGSTensor& t) : FTensor(first_row, num, t), tdims(t.tdims)
   {
   }
 
   // Constructs a slice from a fully symmetric sparse tensor
-  FGSTensor(const FSSparseTensor &t, const IntSequence &ss,
-            const IntSequence &coor, TensorDimens td);
+  FGSTensor(const FSSparseTensor& t, const IntSequence& ss, const IntSequence& coor,
+            TensorDimens td);
 
   // Constructs a slice from a fully symmetric dense tensor
-  FGSTensor(const FFSTensor &t, const IntSequence &ss,
-            const IntSequence &coor, TensorDimens td);
+  FGSTensor(const FFSTensor& t, const IntSequence& ss, const IntSequence& coor, TensorDimens td);
 
   // Converting constructors
-  explicit FGSTensor(const UGSTensor &ut);
-  explicit FGSTensor(const GSSparseTensor &sp);
-  explicit FGSTensor(FFSTensor &t)
-    : FTensor(0, t.nrows(), t), tdims(t.nvar(), t.dimen())
+  explicit FGSTensor(const UGSTensor& ut);
+  explicit FGSTensor(const GSSparseTensor& sp);
+  explicit FGSTensor(FFSTensor& t) : FTensor(0, t.nrows(), t), tdims(t.nvar(), t.dimen())
   {
   }
 
   ~FGSTensor() override = default;
 
-  void increment(IntSequence &v) const override;
+  void increment(IntSequence& v) const override;
   void
-  decrement(IntSequence &v) const override
+  decrement(IntSequence& v) const override
   {
     tdims.decrement(v);
   }
   std::unique_ptr<UTensor> unfold() const override;
-  const TensorDimens &
+  const TensorDimens&
   getDims() const
   {
     return tdims;
   }
-  const Symmetry &
+  const Symmetry&
   getSym() const
   {
     return getDims().getSym();
@@ -184,11 +182,10 @@ public:
 
       [r_xⁱzᵏ]_α₁…αᵢγ₁…γₖ = [t_xⁱyʲzᵏ]_α₁…αᵢβ₁…βⱼγ₁…γₖ·[c]^β₁…βⱼ
   */
-  void contractAndAdd(int i, FGSTensor &out,
-                      const FRSingleTensor &col) const;
+  void contractAndAdd(int i, FGSTensor& out, const FRSingleTensor& col) const;
 
   int
-  getOffset(const IntSequence &v) const override
+  getOffset(const IntSequence& v) const override
   {
     return tdims.calcFoldOffset(v);
   }
@@ -204,59 +201,58 @@ class UGSTensor : public UTensor
   friend class FGSTensor;
 
   const TensorDimens tdims;
+
 public:
-  UGSTensor(int r, TensorDimens td)
-    : UTensor(indor::along_col, td.getNVX(), r,
-              td.calcUnfoldMaxOffset(), td.dimen()), tdims(std::move(td))
+  UGSTensor(int r, TensorDimens td) :
+      UTensor(indor::along_col, td.getNVX(), r, td.calcUnfoldMaxOffset(), td.dimen()),
+      tdims(std::move(td))
   {
   }
 
-  UGSTensor(const UGSTensor &) = default;
-  UGSTensor(UGSTensor &&) = default;
+  UGSTensor(const UGSTensor&) = default;
+  UGSTensor(UGSTensor&&) = default;
 
-  UGSTensor(int first_row, int num, UGSTensor &t)
-    : UTensor(first_row, num, t), tdims(t.tdims)
+  UGSTensor(int first_row, int num, UGSTensor& t) : UTensor(first_row, num, t), tdims(t.tdims)
   {
   }
 
   // Constructs a slice from fully symmetric sparse tensor
-  UGSTensor(const FSSparseTensor &t, const IntSequence &ss,
-            const IntSequence &coor, TensorDimens td);
+  UGSTensor(const FSSparseTensor& t, const IntSequence& ss, const IntSequence& coor,
+            TensorDimens td);
 
   // Constructs a slice from fully symmetric dense unfolded tensor
-  UGSTensor(const UFSTensor &t, const IntSequence &ss,
-            const IntSequence &coor, TensorDimens td);
+  UGSTensor(const UFSTensor& t, const IntSequence& ss, const IntSequence& coor, TensorDimens td);
 
   // Converting constructors
-  explicit UGSTensor(const FGSTensor &ft);
-  explicit UGSTensor(UFSTensor &t)
-    : UTensor(0, t.nrows(), t), tdims(t.nvar(), t.dimen())
+  explicit UGSTensor(const FGSTensor& ft);
+  explicit UGSTensor(UFSTensor& t) : UTensor(0, t.nrows(), t), tdims(t.nvar(), t.dimen())
   {
   }
 
   ~UGSTensor() override = default;
 
-  void increment(IntSequence &v) const override;
-  void decrement(IntSequence &v) const override;
+  void increment(IntSequence& v) const override;
+  void decrement(IntSequence& v) const override;
   std::unique_ptr<FTensor> fold() const override;
-  const TensorDimens &
+  const TensorDimens&
   getDims() const
   {
     return tdims;
   }
-  const Symmetry &
+  const Symmetry&
   getSym() const
   {
     return getDims().getSym();
   }
 
-  void contractAndAdd(int i, UGSTensor &out,
-                      const URSingleTensor &col) const;
-  int getOffset(const IntSequence &v) const override;
+  void contractAndAdd(int i, UGSTensor& out, const URSingleTensor& col) const;
+  int getOffset(const IntSequence& v) const override;
+
 private:
   void unfoldData();
+
 public:
-  index getFirstIndexOf(const index &in) const;
+  index getFirstIndexOf(const index& in) const;
 };
 
 #endif
diff --git a/mex/sources/libkorder/tl/int_sequence.cc b/mex/sources/libkorder/tl/int_sequence.cc
index cc1abae578abfb916ed99e092b86cd69331d1d06..1d4f43115da79c841eea4ba597bfca53fe429b73 100644
--- a/mex/sources/libkorder/tl/int_sequence.cc
+++ b/mex/sources/libkorder/tl/int_sequence.cc
@@ -19,16 +19,16 @@
  */
 
 #include "int_sequence.hh"
+#include "pascal_triangle.hh"
 #include "symmetry.hh"
 #include "tl_exception.hh"
-#include "pascal_triangle.hh"
 
 #include <iostream>
 #include <limits>
 #include <numeric>
 
 IntSequence
-IntSequence::unfold(const Symmetry &sy) const
+IntSequence::unfold(const Symmetry& sy) const
 {
   IntSequence r(sy.dimen());
   int k = 0;
@@ -47,7 +47,7 @@ IntSequence::getSymmetry() const
     r[p] = 1;
   for (int i = 1; i < size(); i++)
     {
-      if (operator[](i) != operator[](i-1))
+      if (operator[](i) != operator[](i - 1))
         p++;
       r[p]++;
     }
@@ -57,41 +57,40 @@ IntSequence::getSymmetry() const
 IntSequence
 IntSequence::insert(int i) const
 {
-  IntSequence r(size()+1);
+  IntSequence r(size() + 1);
   int j;
   for (j = 0; j < size() && operator[](j) < i; j++)
     r[j] = operator[](j);
   r[j] = i;
   for (; j < size(); j++)
-    r[j+1] = operator[](j);
+    r[j + 1] = operator[](j);
   return r;
 }
 
 IntSequence
 IntSequence::insert(int i, int pos) const
 {
-  TL_RAISE_IF(pos < 0 || pos > size(),
-              "Wrong position for IntSequence::insert()");
-  IntSequence r(size()+1);
+  TL_RAISE_IF(pos < 0 || pos > size(), "Wrong position for IntSequence::insert()");
+  IntSequence r(size() + 1);
   int j;
   for (j = 0; j < pos; j++)
     r[j] = operator[](j);
   r[j] = i;
   for (; j < size(); j++)
-    r[j+1] = operator[](j);
+    r[j + 1] = operator[](j);
   return r;
 }
 
-IntSequence &
-IntSequence::operator=(const IntSequence &s)
+IntSequence&
+IntSequence::operator=(const IntSequence& s)
 {
   TL_RAISE_IF(length != s.length, "Wrong length for in-place IntSequence::operator=");
   std::copy_n(s.data, length, data);
   return *this;
 }
 
-IntSequence &
-IntSequence::operator=(IntSequence &&s)
+IntSequence&
+IntSequence::operator=(IntSequence&& s)
 {
   TL_RAISE_IF(length != s.length, "Wrong length for in-place IntSequence::operator=");
   std::copy_n(s.data, length, data);
@@ -99,24 +98,21 @@ IntSequence::operator=(IntSequence &&s)
 }
 
 bool
-IntSequence::operator==(const IntSequence &s) const
+IntSequence::operator==(const IntSequence& s) const
 {
-  return std::equal(data, data+length,
-                    s.data, s.data+s.length);
+  return std::equal(data, data + length, s.data, s.data + s.length);
 }
 
 bool
-IntSequence::operator<(const IntSequence &s) const
+IntSequence::operator<(const IntSequence& s) const
 {
-  return std::lexicographical_compare(data, data+length,
-                                      s.data, s.data+s.length);
+  return std::lexicographical_compare(data, data + length, s.data, s.data + s.length);
 }
 
 bool
-IntSequence::lessEq(const IntSequence &s) const
+IntSequence::lessEq(const IntSequence& s) const
 {
-  TL_RAISE_IF(size() != s.size(),
-              "Sequence with different lengths in IntSequence::lessEq");
+  TL_RAISE_IF(size() != s.size(), "Sequence with different lengths in IntSequence::lessEq");
 
   int i = 0;
   while (i < size() && operator[](i) <= s[i])
@@ -125,10 +121,9 @@ IntSequence::lessEq(const IntSequence &s) const
 }
 
 bool
-IntSequence::less(const IntSequence &s) const
+IntSequence::less(const IntSequence& s) const
 {
-  TL_RAISE_IF(size() != s.size(),
-              "Sequence with different lengths in IntSequence::less");
+  TL_RAISE_IF(size() != s.size(), "Sequence with different lengths in IntSequence::less");
 
   int i = 0;
   while (i < size() && operator[](i) < s[i])
@@ -139,26 +134,26 @@ IntSequence::less(const IntSequence &s) const
 void
 IntSequence::sort()
 {
-  std::sort(data, data+length);
+  std::sort(data, data + length);
 }
 
 void
 IntSequence::monotone()
 {
   for (int i = 1; i < length; i++)
-    if (operator[](i-1) > operator[](i))
-      operator[](i) = operator[](i-1);
+    if (operator[](i - 1) > operator[](i))
+      operator[](i) = operator[](i - 1);
 }
 
 void
-IntSequence::pmonotone(const Symmetry &s)
+IntSequence::pmonotone(const Symmetry& s)
 {
   int cum = 0;
   for (int i = 0; i < s.num(); i++)
     {
       for (int j = cum + 1; j < cum + s[i]; j++)
-        if (operator[](j-1) > operator[](j))
-          operator[](j) = operator[](j-1);
+        if (operator[](j - 1) > operator[](j))
+          operator[](j) = operator[](j - 1);
       cum += s[i];
     }
 }
@@ -166,23 +161,22 @@ IntSequence::pmonotone(const Symmetry &s)
 int
 IntSequence::sum() const
 {
-  return std::accumulate(data, data+length, 0);
+  return std::accumulate(data, data + length, 0);
 }
 
 int
 IntSequence::mult(int i1, int i2) const
 {
-  return std::accumulate(data+i1, data+i2,
-                         1, std::multiplies<int>());
+  return std::accumulate(data + i1, data + i2, 1, std::multiplies<int>());
 }
 
 int
 IntSequence::getPrefixLength() const
 {
   int i = 0;
-  while (i+1 < size() && operator[](i+1) == operator[](0))
+  while (i + 1 < size() && operator[](i + 1) == operator[](0))
     i++;
-  return i+1;
+  return i + 1;
 }
 
 int
@@ -192,7 +186,7 @@ IntSequence::getNumDistinct() const
   if (length > 0)
     res++;
   for (int i = 1; i < length; i++)
-    if (operator[](i) != operator[](i-1))
+    if (operator[](i) != operator[](i - 1))
       res++;
   return res;
 }
@@ -202,7 +196,7 @@ IntSequence::getMax() const
 {
   if (length == 0)
     return std::numeric_limits<int>::min();
-  return *std::max_element(data, data+length);
+  return *std::max_element(data, data + length);
 }
 
 void
@@ -213,19 +207,17 @@ IntSequence::add(int i)
 }
 
 void
-IntSequence::add(int f, const IntSequence &s)
+IntSequence::add(int f, const IntSequence& s)
 {
-  TL_RAISE_IF(size() != s.size(),
-              "Wrong sequence length in IntSequence::add");
+  TL_RAISE_IF(size() != s.size(), "Wrong sequence length in IntSequence::add");
   for (int j = 0; j < size(); j++)
-    operator[](j) += f*s[j];
+    operator[](j) += f * s[j];
 }
 
 bool
 IntSequence::isPositive() const
 {
-  return std::all_of(data, data+length,
-                     [](int x) { return x >= 0; });
+  return std::all_of(data, data + length, [](int x) { return x >= 0; });
 }
 
 bool
@@ -233,14 +225,13 @@ IntSequence::isConstant() const
 {
   if (length < 2)
     return true;
-  return std::all_of(data+1, data+length,
-                     [this](int x) { return x == operator[](0); });
+  return std::all_of(data + 1, data + length, [this](int x) { return x == operator[](0); });
 }
 
 bool
 IntSequence::isSorted() const
 {
-  return std::is_sorted(data, data+length);
+  return std::is_sorted(data, data + length);
 }
 
 /* Debug print. */
diff --git a/mex/sources/libkorder/tl/int_sequence.hh b/mex/sources/libkorder/tl/int_sequence.hh
index a66ec19678d91d0e29deb35e130dc9875f104872..f37815ac3cf69079cf6fb04e223e82fa50416534 100644
--- a/mex/sources/libkorder/tl/int_sequence.hh
+++ b/mex/sources/libkorder/tl/int_sequence.hh
@@ -42,10 +42,10 @@
 #ifndef INT_SEQUENCE_H
 #define INT_SEQUENCE_H
 
-#include <vector>
 #include <algorithm>
 #include <initializer_list>
 #include <utility>
+#include <vector>
 
 /* The implementation of IntSequence is straightforward. It has a pointer
    ‘data’, an ‘offset’ integer indicating the beginning of the data relatively
@@ -59,76 +59,72 @@
 class Symmetry;
 class IntSequence
 {
-  int *data;
+  int* data;
   int length;
-  bool destroy{true};
+  bool destroy {true};
+
 public:
   // Constructor allocating a given length of (uninitialized) data
-  explicit IntSequence(int l)
-    : data{new int[l]}, length{l}
+  explicit IntSequence(int l) : data {new int[l]}, length {l}
   {
   }
   // Constructor allocating and then initializing all members to a given number
-  IntSequence(int l, int n)
-    : data{new int[l]}, length{l}
+  IntSequence(int l, int n) : data {new int[l]}, length {l}
   {
     std::fill_n(data, length, n);
   }
   /* Constructor using an initializer list (gives the contents of the
      IntSequence, similarly to std::vector) */
-  IntSequence(std::initializer_list<int> init)
-    : data{new int[init.size()]},
-      length{static_cast<int>(init.size())}
+  IntSequence(std::initializer_list<int> init) :
+      data {new int[init.size()]}, length {static_cast<int>(init.size())}
   {
     std::copy(init.begin(), init.end(), data);
   }
   // Copy constructor
-  IntSequence(const IntSequence &s)
-    : data{new int[s.length]}, length{s.length}
+  IntSequence(const IntSequence& s) : data {new int[s.length]}, length {s.length}
   {
     std::copy_n(s.data, length, data);
   }
   // Move constructor
-  IntSequence(IntSequence &&s) noexcept
-    : data{std::exchange(s.data, nullptr)}, length{std::exchange(s.length, 0)},
-      destroy{std::exchange(s.destroy, false)}
+  IntSequence(IntSequence&& s) noexcept :
+      data {std::exchange(s.data, nullptr)}, length {std::exchange(s.length, 0)},
+      destroy {std::exchange(s.destroy, false)}
   {
   }
   // Subsequence constructor (which shares the data pointer)
-  IntSequence(IntSequence &s, int i1, int i2)
-    : data{s.data+i1}, length{i2-i1}, destroy{false}
+  IntSequence(IntSequence& s, int i1, int i2) :
+      data {s.data + i1}, length {i2 - i1}, destroy {false}
   {
   }
   // Subsequence constructor (without pointer sharing)
-  IntSequence(const IntSequence &s, int i1, int i2)
-    : data{new int[i2-i1]}, length{i2-i1}
+  IntSequence(const IntSequence& s, int i1, int i2) : data {new int[i2 - i1]}, length {i2 - i1}
   {
-    std::copy_n(s.data+i1, length, data);
+    std::copy_n(s.data + i1, length, data);
   }
   /* Unfolds a given integer sequence with respect to a given symmetry. If for
      example the sequence is (a,b) and the symmetry is (2,3), then the
      result is (a,a,b,b,b). */
-  IntSequence unfold(const Symmetry &sy) const;
+  IntSequence unfold(const Symmetry& sy) const;
 
   /* Constructs a symmetry from the integer sequence (supposed to be ordered) as
      a symmetry counting successively equal items. For instance the sequence
      (a,a,a,b,c,c,d,d,d,d) produces symmetry (3,1,2,4). */
   Symmetry getSymmetry() const;
 
-  IntSequence &operator=(const IntSequence &s);
-  IntSequence &operator=(IntSequence &&s);
+  IntSequence& operator=(const IntSequence& s);
+  IntSequence& operator=(IntSequence&& s);
   virtual ~IntSequence()
   {
     if (destroy)
       delete[] data;
   }
-  bool operator==(const IntSequence &s) const;
+  bool operator==(const IntSequence& s) const;
   bool
-  operator!=(const IntSequence &s) const
+  operator!=(const IntSequence& s) const
   {
     return !operator==(s);
   }
-  int &
+  int&
   operator[](int i)
   {
     return data[i];
@@ -147,14 +143,14 @@ public:
   /* We provide two orderings. The first operator<() is the linear
      lexicographic ordering, the second less() is the non-linear Cartesian
      ordering. */
-  bool operator<(const IntSequence &s) const;
+  bool operator<(const IntSequence& s) const;
   bool
-  operator<=(const IntSequence &s) const
+  operator<=(const IntSequence& s) const
   {
     return (operator==(s) || operator<(s));
   }
-  bool lessEq(const IntSequence &s) const;
-  bool less(const IntSequence &s) const;
+  bool lessEq(const IntSequence& s) const;
+  bool less(const IntSequence& s) const;
 
   // Inserts an element into an ordered sequence
   IntSequence insert(int i) const;
@@ -173,8 +169,7 @@ public:
    symmetry. So the subsequence given by the symmetry classes are
    monotonized. For example, if the symmetry is y²u³, and the
    IntSequence is (5,3,1,6,4), the result is (5,5,1,6,6). */
-  void pmonotone(const Symmetry &s);
-
+  void pmonotone(const Symmetry& s);
 
   // Returns the sum of all elements. Useful for symmetries
   int sum() const;
@@ -190,7 +185,7 @@ public:
     return mult(0, length);
   }
   void add(int i);
-  void add(int f, const IntSequence &s);
+  void add(int f, const IntSequence& s);
 
   /* Return the number of identical elements at the beginning of the sequence. */
   int getPrefixLength() const;
diff --git a/mex/sources/libkorder/tl/kron_prod.cc b/mex/sources/libkorder/tl/kron_prod.cc
index 3a78bd17b2594548346b6262abebc1e353b5b9a2..dcd0f57913bd4a12928002ef9ebd0c8aacebb8b6 100644
--- a/mex/sources/libkorder/tl/kron_prod.cc
+++ b/mex/sources/libkorder/tl/kron_prod.cc
@@ -34,12 +34,10 @@
 
    Then we fork according to i. */
 
-KronProdDimens::KronProdDimens(const KronProdDimens &kd, int i)
-  : rows((i == 0 || i == kd.dimen()-1) ? 2 : 3),
-    cols((i == 0 || i == kd.dimen()-1) ? 2 : 3)
+KronProdDimens::KronProdDimens(const KronProdDimens& kd, int i) :
+    rows((i == 0 || i == kd.dimen() - 1) ? 2 : 3), cols((i == 0 || i == kd.dimen() - 1) ? 2 : 3)
 {
-  TL_RAISE_IF(i < 0 || i >= kd.dimen(),
-              "Wrong index for pickup in KronProdDimens constructor");
+  TL_RAISE_IF(i < 0 || i >= kd.dimen(), "Wrong index for pickup in KronProdDimens constructor");
 
   int kdim = kd.dimen();
   if (i == 0)
@@ -53,16 +51,16 @@ KronProdDimens::KronProdDimens(const KronProdDimens &kd, int i)
       cols[0] = kd.cols[0];
       cols[1] = rows[1];
     }
-  else if (i == kdim-1)
+  else if (i == kdim - 1)
     {
       // set I⊗A dimensions
       /* The second dimension is taken from ‘kd’. The dimension of the identity
          matrix is the number of columns of A₁⊗…⊗Aₙ₋₁, since the matrix I⊗Aₙ is
          the last. */
-      rows[0] = kd.cols.mult(0, kdim-1);
-      rows[1] = kd.rows[kdim-1];
+      rows[0] = kd.cols.mult(0, kdim - 1);
+      rows[1] = kd.rows[kdim - 1];
       cols[0] = rows[0];
-      cols[1] = kd.cols[kdim-1];
+      cols[1] = kd.cols[kdim - 1];
     }
   else
     {
@@ -75,7 +73,7 @@ KronProdDimens::KronProdDimens(const KronProdDimens &kd, int i)
       cols[0] = rows[0];
       rows[1] = kd.rows[i];
       cols[1] = kd.cols[i];
-      cols[2] = kd.rows.mult(i+1, kdim);
+      cols[2] = kd.rows.mult(i + 1, kdim);
       rows[2] = cols[2];
     }
 }
@@ -84,7 +82,7 @@ KronProdDimens::KronProdDimens(const KronProdDimens &kd, int i)
    out = in·this. */
 
 void
-KronProd::checkDimForMult(const ConstTwoDMatrix &in, const TwoDMatrix &out) const
+KronProd::checkDimForMult(const ConstTwoDMatrix& in, const TwoDMatrix& out) const
 {
   auto [my_rows, my_cols] = kpd.getRC();
   TL_RAISE_IF(in.nrows() != out.nrows() || in.ncols() != my_rows,
@@ -95,21 +93,20 @@ KronProd::checkDimForMult(const ConstTwoDMatrix &in, const TwoDMatrix &out) cons
    store the result in preallocated ‘res’. */
 
 void
-KronProd::kronMult(const ConstVector &v1, const ConstVector &v2,
-                   Vector &res)
+KronProd::kronMult(const ConstVector& v1, const ConstVector& v2, Vector& res)
 {
-  TL_RAISE_IF(res.length() != v1.length()*v2.length(),
+  TL_RAISE_IF(res.length() != v1.length() * v2.length(),
               "Wrong vector lengths in KronProd::kronMult");
   res.zeros();
   for (int i = 0; i < v1.length(); i++)
     {
-      Vector sub(res, i *v2.length(), v2.length());
+      Vector sub(res, i * v2.length(), v2.length());
       sub.add(v1[i], v2);
     }
 }
 
 void
-KronProdAll::setMat(int i, const TwoDMatrix &m)
+KronProdAll::setMat(int i, const TwoDMatrix& m)
 {
   matlist[i] = &m;
   kpd.setRC(i, m.nrows(), m.ncols());
@@ -138,7 +135,7 @@ KronProdAll::isUnit() const
    partitions of ‘in’, and ‘id_cols’ is m. We employ level-2 BLAS. */
 
 void
-KronProdIA::mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const
+KronProdIA::mult(const ConstTwoDMatrix& in, TwoDMatrix& out) const
 {
   checkDimForMult(in, out);
 
@@ -154,8 +151,7 @@ KronProdIA::mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const
 }
 
 /* Here we construct KronProdAI from KronProdIAI. It is clear. */
-KronProdAI::KronProdAI(const KronProdIAI &kpiai)
-  : KronProd(KronProdDimens(2)), mat(kpiai.mat)
+KronProdAI::KronProdAI(const KronProdIAI& kpiai) : KronProd(KronProdDimens(2)), mat(kpiai.mat)
 {
   kpd.rows[0] = mat.nrows();
   kpd.cols[0] = mat.ncols();
@@ -174,17 +170,16 @@ KronProdAI::KronProdAI(const KronProdIAI &kpiai)
 
    For cases where the leading dimension is not equal to the number of
    rows, we partition the matrix A⊗I into m×n square partitions aᵢⱼI.
-   Therefore, we partition B into m partitions (B₁ B₂ … Bₘ). Each partition of B has the same number of
-   columns as the identity matrix. If R denotes the resulting matrix,
-   then it can be partitioned into n partitions
-   (R₁ R₂ … Rₙ). Each partition of R has the same number of
-   columns as the identity matrix. Then we have Rᵢ=∑aⱼᵢBⱼ.
+   Therefore, we partition B into m partitions (B₁ B₂ … Bₘ). Each partition of B has the same number
+   of columns as the identity matrix. If R denotes the resulting matrix, then it can be partitioned
+   into n partitions (R₁ R₂ … Rₙ). Each partition of R has the same number of columns as the
+   identity matrix. Then we have Rᵢ=∑aⱼᵢBⱼ.
 
    In the implementation, ‘outi’ is Rᵢ, ‘ini’ is Bⱼ, and ‘id_cols’ is the
    dimension of the identity matrix. */
 
 void
-KronProdAI::mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const
+KronProdAI::mult(const ConstTwoDMatrix& in, TwoDMatrix& out) const
 {
   checkDimForMult(in, out);
 
@@ -193,8 +188,8 @@ KronProdAI::mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const
 
   if (in.getLD() == in.nrows())
     {
-      ConstTwoDMatrix in_resh(in.nrows()*id_cols, a.nrows(), in.getData());
-      TwoDMatrix out_resh(in.nrows()*id_cols, a.ncols(), out.getData());
+      ConstTwoDMatrix in_resh(in.nrows() * id_cols, a.nrows(), in.getData());
+      TwoDMatrix out_resh(in.nrows() * id_cols, a.ncols(), out.getData());
       out_resh.mult(in_resh, a);
     }
   else
@@ -202,10 +197,10 @@ KronProdAI::mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const
       out.zeros();
       for (int i = 0; i < a.ncols(); i++)
         {
-          TwoDMatrix outi(out, i *id_cols, id_cols);
+          TwoDMatrix outi(out, i * id_cols, id_cols);
           for (int j = 0; j < a.nrows(); j++)
             {
-              ConstTwoDMatrix ini(in, j *id_cols, id_cols);
+              ConstTwoDMatrix ini(in, j * id_cols, id_cols);
               outi.add(a.get(j, i), ini);
             }
         }
@@ -223,7 +218,7 @@ KronProdAI::mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const
    and ‘out_bl_width’ are the rows and cols of A⊗I. */
 
 void
-KronProdIAI::mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const
+KronProdIAI::mult(const ConstTwoDMatrix& in, TwoDMatrix& out) const
 {
   checkDimForMult(in, out);
 
@@ -234,8 +229,8 @@ KronProdIAI::mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const
 
   for (int i = 0; i < id_cols; i++)
     {
-      TwoDMatrix outi(out, i *out_bl_width, out_bl_width);
-      ConstTwoDMatrix ini(in, i *in_bl_width, in_bl_width);
+      TwoDMatrix outi(out, i * out_bl_width, out_bl_width);
+      ConstTwoDMatrix ini(in, i * in_bl_width, in_bl_width);
       akronid.mult(ini, outi);
     }
 }
@@ -254,7 +249,7 @@ KronProdIAI::mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const
    handle ‘last’ safely also if no calcs are done. */
 
 void
-KronProdAll::mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const
+KronProdAll::mult(const ConstTwoDMatrix& in, TwoDMatrix& out) const
 {
   // quick copy if product is unit
   if (isUnit())
@@ -298,13 +293,13 @@ KronProdAll::mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const
       akronid.mult(in, *last);
     }
   else
-    last = std::make_unique<TwoDMatrix>(in.nrows(), in.ncols(), Vector{in.getData()});
+    last = std::make_unique<TwoDMatrix>(in.nrows(), in.ncols(), Vector {in.getData()});
 
   // perform intermediate multiplications by I⊗Aᵢ⊗I
   /* Here we go through all I⊗Aᵢ⊗I, construct the product, allocate new storage
      for result ‘newlast’, perform the multiplication and set ‘last’ to
      ‘newlast’. */
-  for (int i = 1; i < dimen()-1; i++)
+  for (int i = 1; i < dimen() - 1; i++)
     if (matlist[i])
       {
         KronProdIAI interkron(*this, i);
@@ -315,7 +310,7 @@ KronProdAll::mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const
       }
 
   // perform last multiplication by I⊗Aₙ
-  if (matlist[dimen()-1])
+  if (matlist[dimen() - 1])
     {
       KronProdIA idkrona(*this);
       idkrona.mult(*last, out);
@@ -329,17 +324,16 @@ KronProdAll::mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const
    returned. */
 
 std::unique_ptr<Vector>
-KronProdAll::multRows(const IntSequence &irows) const
+KronProdAll::multRows(const IntSequence& irows) const
 {
-  TL_RAISE_IF(irows.size() != dimen(),
-              "Wrong length of row indices in KronProdAll::multRows");
+  TL_RAISE_IF(irows.size() != dimen(), "Wrong length of row indices in KronProdAll::multRows");
 
   std::unique_ptr<Vector> last;
   std::unique_ptr<ConstVector> row;
   std::vector<std::unique_ptr<Vector>> to_delete;
   for (int i = 0; i < dimen(); i++)
     {
-      int j = dimen()-1-i;
+      int j = dimen() - 1 - i;
 
       // set ‘row’ to the number of rows of j-th matrix
       /* If the j-th matrix is a real matrix, then the row is constructed from
@@ -363,7 +357,7 @@ KronProdAll::multRows(const IntSequence &irows) const
          ‘row’. */
       if (last)
         {
-          auto newlast = std::make_unique<Vector>(last->length()*row->length());
+          auto newlast = std::make_unique<Vector>(last->length() * row->length());
           kronMult(*row, ConstVector(*last), *newlast);
           last = std::move(newlast);
         }
@@ -387,24 +381,24 @@ KronProdAllOptim::optimizeOrder()
   for (int i = 0; i < dimen(); i++)
     {
       int swaps = 0;
-      for (int j = 0; j < dimen()-1; j++)
-        if (static_cast<double>(kpd.rows[j])/kpd.cols[j]
-            < static_cast<double>(kpd.rows[j+1])/kpd.cols[j+1])
+      for (int j = 0; j < dimen() - 1; j++)
+        if (static_cast<double>(kpd.rows[j]) / kpd.cols[j]
+            < static_cast<double>(kpd.rows[j + 1]) / kpd.cols[j + 1])
           {
             // swap dimensions and matrices at j and j+1
-            int s = kpd.rows[j+1];
-            kpd.rows[j+1] = kpd.rows[j];
+            int s = kpd.rows[j + 1];
+            kpd.rows[j + 1] = kpd.rows[j];
             kpd.rows[j] = s;
-            s = kpd.cols[j+1];
-            kpd.cols[j+1] = kpd.cols[j];
+            s = kpd.cols[j + 1];
+            kpd.cols[j + 1] = kpd.cols[j];
             kpd.cols[j] = s;
-            const TwoDMatrix *m = matlist[j+1];
-            matlist[j+1] = matlist[j];
+            const TwoDMatrix* m = matlist[j + 1];
+            matlist[j + 1] = matlist[j];
             matlist[j] = m;
 
             // project the swap to the permutation ‘oper’
-            s = oper.getMap()[j+1];
-            oper.getMap()[j+1] = oper.getMap()[j];
+            s = oper.getMap()[j + 1];
+            oper.getMap()[j + 1] = oper.getMap()[j];
             oper.getMap()[j] = s;
             swaps++;
           }
diff --git a/mex/sources/libkorder/tl/kron_prod.hh b/mex/sources/libkorder/tl/kron_prod.hh
index eee195770d4830bfb55f78bfdd8b8d99da56ff77..b18c350e5636c110ec232d6cdfb37241879ad744 100644
--- a/mex/sources/libkorder/tl/kron_prod.hh
+++ b/mex/sources/libkorder/tl/kron_prod.hh
@@ -40,13 +40,13 @@
 #ifndef KRON_PROD_H
 #define KRON_PROD_H
 
+#include <memory>
 #include <utility>
 #include <vector>
-#include <memory>
 
-#include "twod_matrix.hh"
-#include "permutation.hh"
 #include "int_sequence.hh"
+#include "permutation.hh"
+#include "twod_matrix.hh"
 
 class KronProdAll;
 class KronProdAllOptim;
@@ -64,29 +64,30 @@ class KronProdDimens
   friend class KronProdIA;
   friend class KronProdIAI;
   friend class KronProdAI;
+
 private:
   IntSequence rows;
   IntSequence cols;
+
 public:
   // Initializes to a given dimension, and all rows and cols are set to zeros
-  KronProdDimens(int dim)
-    : rows(dim, 0), cols(dim, 0)
+  KronProdDimens(int dim) : rows(dim, 0), cols(dim, 0)
   {
   }
-  KronProdDimens(const KronProdDimens &kd) = default;
-  KronProdDimens(KronProdDimens &&kd) = default;
+  KronProdDimens(const KronProdDimens& kd) = default;
+  KronProdDimens(KronProdDimens&& kd) = default;
 
   /* Takes dimensions of A₁⊗…⊗Aₙ, and makes dimensions of A₁⊗I, I⊗Aᵢ⊗I or I⊗Aₙ
      for a given i. The dimensions of identity matrices are such that
      A₁⊗…⊗Aₙ=(A₁⊗I)·…·(I⊗Aᵢ⊗I)·…·(I⊗Aₙ). Note that the matrices on the right do
      not commute only because sizes of identity matrices which are then given
      by this ordering. */
-  KronProdDimens(const KronProdDimens &kd, int i);
+  KronProdDimens(const KronProdDimens& kd, int i);
 
-  KronProdDimens &operator=(const KronProdDimens &kd) = default;
-  KronProdDimens &operator=(KronProdDimens &&kd) = default;
+  KronProdDimens& operator=(const KronProdDimens& kd) = default;
+  KronProdDimens& operator=(KronProdDimens&& kd) = default;
   bool
-  operator==(const KronProdDimens &kd) const
+  operator==(const KronProdDimens& kd) const
   {
     return rows == kd.rows && cols == kd.cols;
   }
@@ -105,12 +106,12 @@ public:
   std::pair<int, int>
   getRC(int i) const
   {
-    return { rows[i], cols[i] };
+    return {rows[i], cols[i]};
   }
   std::pair<int, int>
   getRC() const
   {
-    return { rows.mult(), cols.mult() };
+    return {rows.mult(), cols.mult()};
   }
   int
   nrows() const
@@ -148,17 +149,16 @@ class KronProd
 {
 protected:
   KronProdDimens kpd;
+
 public:
-  KronProd(int dim)
-    : kpd(dim)
+  KronProd(int dim) : kpd(dim)
   {
   }
-  KronProd(const KronProdDimens &kd)
-    : kpd(kd)
+  KronProd(const KronProdDimens& kd) : kpd(kd)
   {
   }
-  KronProd(const KronProd &kp) = default;
-  KronProd(KronProd &&kp) = default;
+  KronProd(const KronProd& kp) = default;
+  KronProd(KronProd&& kp) = default;
   virtual ~KronProd() = default;
 
   int
@@ -167,22 +167,21 @@ public:
     return kpd.dimen();
   }
 
-  virtual void mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const = 0;
+  virtual void mult(const ConstTwoDMatrix& in, TwoDMatrix& out) const = 0;
   void
-  mult(const TwoDMatrix &in, TwoDMatrix &out) const
+  mult(const TwoDMatrix& in, TwoDMatrix& out) const
   {
     mult(ConstTwoDMatrix(in), out);
   }
 
-  void checkDimForMult(const ConstTwoDMatrix &in, const TwoDMatrix &out) const;
+  void checkDimForMult(const ConstTwoDMatrix& in, const TwoDMatrix& out) const;
   void
-  checkDimForMult(const TwoDMatrix &in, const TwoDMatrix &out) const
+  checkDimForMult(const TwoDMatrix& in, const TwoDMatrix& out) const
   {
     checkDimForMult(ConstTwoDMatrix(in), out);
   }
 
-  static void kronMult(const ConstVector &v1, const ConstVector &v2,
-                       Vector &res);
+  static void kronMult(const ConstVector& v1, const ConstVector& v2, Vector& res);
 
   int
   nrows() const
@@ -225,24 +224,26 @@ class KronProdAll : public KronProd
   friend class KronProdIA;
   friend class KronProdIAI;
   friend class KronProdAI;
+
 protected:
-  std::vector<const TwoDMatrix *> matlist;
+  std::vector<const TwoDMatrix*> matlist;
+
 public:
-  KronProdAll(int dim)
-    : KronProd(dim), matlist(dim)
+  KronProdAll(int dim) : KronProd(dim), matlist(dim)
   {
   }
   ~KronProdAll() override = default;
-  void setMat(int i, const TwoDMatrix &m);
+  void setMat(int i, const TwoDMatrix& m);
   void setUnit(int i, int n);
-  const TwoDMatrix &
+  const TwoDMatrix&
   getMat(int i) const
   {
     return *(matlist[i]);
   }
 
-  void mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const override;
-  std::unique_ptr<Vector> multRows(const IntSequence &irows) const;
+  void mult(const ConstTwoDMatrix& in, TwoDMatrix& out) const override;
+  std::unique_ptr<Vector> multRows(const IntSequence& irows) const;
+
 private:
   bool isUnit() const;
 };
@@ -281,13 +282,13 @@ class KronProdAllOptim : public KronProdAll
 {
 protected:
   Permutation oper;
+
 public:
-  KronProdAllOptim(int dim)
-    : KronProdAll(dim), oper(dim)
+  KronProdAllOptim(int dim) : KronProdAll(dim), oper(dim)
   {
   }
   void optimizeOrder();
-  const Permutation &
+  const Permutation&
   getPer() const
   {
     return oper;
@@ -300,14 +301,14 @@ public:
 class KronProdIA : public KronProd
 {
   friend class KronProdAll;
-  const TwoDMatrix &mat;
+  const TwoDMatrix& mat;
+
 public:
-  KronProdIA(const KronProdAll &kpa)
-    : KronProd(KronProdDimens(kpa.kpd, kpa.dimen()-1)),
-      mat(kpa.getMat(kpa.dimen()-1))
+  KronProdIA(const KronProdAll& kpa) :
+      KronProd(KronProdDimens(kpa.kpd, kpa.dimen() - 1)), mat(kpa.getMat(kpa.dimen() - 1))
   {
   }
-  void mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const override;
+  void mult(const ConstTwoDMatrix& in, TwoDMatrix& out) const override;
 };
 
 /* This class represents A⊗I. We have only one reference to the matrix, which
@@ -317,16 +318,15 @@ class KronProdAI : public KronProd
 {
   friend class KronProdIAI;
   friend class KronProdAll;
-  const TwoDMatrix &mat;
+  const TwoDMatrix& mat;
+
 public:
-  KronProdAI(const KronProdAll &kpa)
-    : KronProd(KronProdDimens(kpa.kpd, 0)),
-      mat(kpa.getMat(0))
+  KronProdAI(const KronProdAll& kpa) : KronProd(KronProdDimens(kpa.kpd, 0)), mat(kpa.getMat(0))
   {
   }
-  KronProdAI(const KronProdIAI &kpiai);
+  KronProdAI(const KronProdIAI& kpiai);
 
-  void mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const override;
+  void mult(const ConstTwoDMatrix& in, TwoDMatrix& out) const override;
 };
 
 /* This class represents I⊗A⊗I. We have only one reference to the matrix, which
@@ -336,14 +336,14 @@ class KronProdIAI : public KronProd
 {
   friend class KronProdAI;
   friend class KronProdAll;
-  const TwoDMatrix &mat;
+  const TwoDMatrix& mat;
+
 public:
-  KronProdIAI(const KronProdAll &kpa, int i)
-    : KronProd(KronProdDimens(kpa.kpd, i)),
-      mat(kpa.getMat(i))
+  KronProdIAI(const KronProdAll& kpa, int i) :
+      KronProd(KronProdDimens(kpa.kpd, i)), mat(kpa.getMat(i))
   {
   }
-  void mult(const ConstTwoDMatrix &in, TwoDMatrix &out) const override;
+  void mult(const ConstTwoDMatrix& in, TwoDMatrix& out) const override;
 };
 
 #endif
diff --git a/mex/sources/libkorder/tl/normal_moments.cc b/mex/sources/libkorder/tl/normal_moments.cc
index 43014bbc33821842fb5268139848e459151226e5..e5b62ca1c86147f299c73e74a7d618ef7f7d897e 100644
--- a/mex/sources/libkorder/tl/normal_moments.cc
+++ b/mex/sources/libkorder/tl/normal_moments.cc
@@ -20,13 +20,12 @@
 
 #include <memory>
 
+#include "kron_prod.hh"
 #include "normal_moments.hh"
 #include "permutation.hh"
-#include "kron_prod.hh"
 #include "tl_static.hh"
 
-UNormalMoments::UNormalMoments(int maxdim, const TwoDMatrix &v)
-  : TensorContainer<URSingleTensor>(1)
+UNormalMoments::UNormalMoments(int maxdim, const TwoDMatrix& v) : TensorContainer<URSingleTensor>(1)
 {
   if (maxdim >= 2)
     generateMoments(maxdim, v);
@@ -39,7 +38,7 @@ UNormalMoments::UNormalMoments(int maxdim, const TwoDMatrix &v)
    Here we sequentially construct the Kronecker power ⊗ⁿv and apply Fₙ.
 */
 void
-UNormalMoments::generateMoments(int maxdim, const TwoDMatrix &v)
+UNormalMoments::generateMoments(int maxdim, const TwoDMatrix& v)
 {
   TL_RAISE_IF(v.nrows() != v.ncols(),
               "Variance-covariance matrix is not square in UNormalMoments constructor");
@@ -53,8 +52,7 @@ UNormalMoments::generateMoments(int maxdim, const TwoDMatrix &v)
   for (int d = 4; d <= maxdim; d += 2)
     {
       auto newkronv = std::make_unique<URSingleTensor>(nv, d);
-      KronProd::kronMult(ConstVector(v.getData()),
-                         ConstVector(kronv->getData()),
+      KronProd::kronMult(ConstVector(v.getData()), ConstVector(kronv->getData()),
                          newkronv->getData());
       kronv = std::move(newkronv);
       auto mom = std::make_unique<URSingleTensor>(nv, d);
@@ -69,7 +67,7 @@ UNormalMoments::generateMoments(int maxdim, const TwoDMatrix &v)
          how the Equivalence::apply() method works. */
       mom->zeros();
       const EquivalenceSet eset = TLStatic::getEquiv(d);
-      for (const auto &cit : eset)
+      for (const auto& cit : eset)
         if (selectEquiv(cit))
           {
             Permutation per(cit);
@@ -89,11 +87,11 @@ UNormalMoments::generateMoments(int maxdim, const TwoDMatrix &v)
 /* We return true for an equivalence whose each class has 2 elements. */
 
 bool
-UNormalMoments::selectEquiv(const Equivalence &e)
+UNormalMoments::selectEquiv(const Equivalence& e)
 {
-  if (2*e.numClasses() != e.getN())
+  if (2 * e.numClasses() != e.getN())
     return false;
-  for (const auto &si : e)
+  for (const auto& si : e)
     if (si.length() != 2)
       return false;
   return true;
@@ -101,9 +99,8 @@ UNormalMoments::selectEquiv(const Equivalence &e)
 
 /* Here we go through all the unfolded container, fold each tensor and
    insert it. */
-FNormalMoments::FNormalMoments(const UNormalMoments &moms)
-  : TensorContainer<FRSingleTensor>(1)
+FNormalMoments::FNormalMoments(const UNormalMoments& moms) : TensorContainer<FRSingleTensor>(1)
 {
-  for (const auto &mom : moms)
+  for (const auto& mom : moms)
     insert(std::make_unique<FRSingleTensor>(*(mom.second)));
 }
diff --git a/mex/sources/libkorder/tl/normal_moments.hh b/mex/sources/libkorder/tl/normal_moments.hh
index c12a3ba53102e88039caf73a88fa87c72b1afc11..856a2fbc4c12fad23c1a8ff5481351d4d40bea9c 100644
--- a/mex/sources/libkorder/tl/normal_moments.hh
+++ b/mex/sources/libkorder/tl/normal_moments.hh
@@ -121,16 +121,17 @@
 class UNormalMoments : public TensorContainer<URSingleTensor>
 {
 public:
-  UNormalMoments(int maxdim, const TwoDMatrix &v);
+  UNormalMoments(int maxdim, const TwoDMatrix& v);
+
 private:
-  void generateMoments(int maxdim, const TwoDMatrix &v);
-  static bool selectEquiv(const Equivalence &e);
+  void generateMoments(int maxdim, const TwoDMatrix& v);
+  static bool selectEquiv(const Equivalence& e);
 };
 
 class FNormalMoments : public TensorContainer<FRSingleTensor>
 {
 public:
-  FNormalMoments(const UNormalMoments &moms);
+  FNormalMoments(const UNormalMoments& moms);
 };
 
 #endif
diff --git a/mex/sources/libkorder/tl/permutation.cc b/mex/sources/libkorder/tl/permutation.cc
index 3cbd75df37121a1f8c24e662a233a71fb4a7dd4b..f3afce9b6792f2d6e8f5cfa6f52fae27debfe9ae 100644
--- a/mex/sources/libkorder/tl/permutation.cc
+++ b/mex/sources/libkorder/tl/permutation.cc
@@ -24,7 +24,7 @@
 /* This is easy, we simply apply the map in the fashion s∘m */
 
 void
-Permutation::apply(const IntSequence &src, IntSequence &tar) const
+Permutation::apply(const IntSequence& src, IntSequence& tar) const
 {
   TL_RAISE_IF(src.size() != permap.size() || tar.size() != permap.size(),
               "Wrong sizes of input or output in Permutation::apply");
@@ -33,7 +33,7 @@ Permutation::apply(const IntSequence &src, IntSequence &tar) const
 }
 
 void
-Permutation::apply(IntSequence &tar) const
+Permutation::apply(IntSequence& tar) const
 {
   IntSequence tmp(tar);
   apply(tmp, tar);
@@ -54,7 +54,7 @@ int
 Permutation::tailIdentity() const
 {
   int i = permap.size();
-  while (i > 0 && permap[i-1] == i-1)
+  while (i > 0 && permap[i - 1] == i - 1)
     i--;
   return permap.size() - i;
 }
@@ -69,7 +69,7 @@ Permutation::tailIdentity() const
    indices from the sorted ‘s’ already assigned. */
 
 void
-Permutation::computeSortingMap(const IntSequence &s)
+Permutation::computeSortingMap(const IntSequence& s)
 {
   IntSequence srt(s);
   srt.sort();
@@ -80,8 +80,7 @@ Permutation::computeSortingMap(const IntSequence &s)
       int j = 0;
       while (j < s.size() && (flags[j] || srt[j] != s[i]))
         j++;
-      TL_RAISE_IF(j == s.size(),
-                  "Internal algorithm error in Permutation::computeSortingMap");
+      TL_RAISE_IF(j == s.size(), "Internal algorithm error in Permutation::computeSortingMap");
       flags[j] = 1;
       permap[i] = j;
     }
@@ -92,11 +91,9 @@ PermutationSet::PermutationSet()
   pers.emplace_back(1);
 }
 
-PermutationSet::PermutationSet(const PermutationSet &sp, int n)
-  : order(n), size(n*sp.size)
+PermutationSet::PermutationSet(const PermutationSet& sp, int n) : order(n), size(n * sp.size)
 {
-  TL_RAISE_IF(n != sp.order+1,
-              "Wrong new order in PermutationSet constructor");
+  TL_RAISE_IF(n != sp.order + 1, "Wrong new order in PermutationSet constructor");
 
   for (int i = 0; i < sp.size; i++)
     for (int j = 0; j < order; j++)
@@ -104,10 +101,9 @@ PermutationSet::PermutationSet(const PermutationSet &sp, int n)
 }
 
 std::vector<Permutation>
-PermutationSet::getPreserving(const IntSequence &s) const
+PermutationSet::getPreserving(const IntSequence& s) const
 {
-  TL_RAISE_IF(s.size() != order,
-              "Wrong sequence length in PermutationSet::getPreserving");
+  TL_RAISE_IF(s.size() != order, "Wrong sequence length in PermutationSet::getPreserving");
 
   std::vector<Permutation> res;
   IntSequence tmp(s.size());
@@ -127,7 +123,7 @@ PermutationBundle::PermutationBundle(int nmax)
   generateUpTo(nmax);
 }
 
-const PermutationSet &
+const PermutationSet&
 PermutationBundle::get(int n) const
 {
   if (n > static_cast<int>(bundle.size()) || n < 1)
@@ -136,7 +132,7 @@ PermutationBundle::get(int n) const
       return bundle[0];
     }
   else
-    return bundle[n-1];
+    return bundle[n - 1];
 }
 
 void
@@ -146,6 +142,6 @@ PermutationBundle::generateUpTo(int nmax)
     bundle.emplace_back();
 
   int curmax = bundle.size();
-  for (int n = curmax+1; n <= nmax; n++)
+  for (int n = curmax + 1; n <= nmax; n++)
     bundle.emplace_back(bundle.back(), n);
 }
diff --git a/mex/sources/libkorder/tl/permutation.hh b/mex/sources/libkorder/tl/permutation.hh
index 19c4a50ac442f89797c9ef8572026c2c663b7512..65b12a135c73cfbeef1a99339b4f8e9ff8dc16ee 100644
--- a/mex/sources/libkorder/tl/permutation.hh
+++ b/mex/sources/libkorder/tl/permutation.hh
@@ -48,8 +48,8 @@
 #ifndef PERMUTATION_H
 #define PERMUTATION_H
 
-#include "int_sequence.hh"
 #include "equivalence.hh"
+#include "int_sequence.hh"
 
 #include <vector>
 
@@ -69,39 +69,34 @@ class Permutation
 {
 protected:
   IntSequence permap;
+
 public:
-  explicit Permutation(int len)
-    : permap(len)
+  explicit Permutation(int len) : permap(len)
   {
     for (int i = 0; i < len; i++)
       permap[i] = i;
   }
-  explicit Permutation(const Equivalence &e)
-    : permap(e.getN())
+  explicit Permutation(const Equivalence& e) : permap(e.getN())
   {
     e.trace(permap);
   }
-  Permutation(const Equivalence &e, const Permutation &per)
-    : permap(e.getN())
+  Permutation(const Equivalence& e, const Permutation& per) : permap(e.getN())
   {
     e.trace(permap, per);
   }
-  explicit Permutation(const IntSequence &s)
-    : permap(s.size())
+  explicit Permutation(const IntSequence& s) : permap(s.size())
   {
     computeSortingMap(s);
   };
-  Permutation(const Permutation &p1, const Permutation &p2)
-    : permap(p2.permap)
+  Permutation(const Permutation& p1, const Permutation& p2) : permap(p2.permap)
   {
     p1.apply(permap);
   }
-  Permutation(const Permutation &p, int i)
-    : permap(p.permap.insert(p.size(), i))
+  Permutation(const Permutation& p, int i) : permap(p.permap.insert(p.size(), i))
   {
   }
   bool
-  operator==(const Permutation &p) const
+  operator==(const Permutation& p) const
   {
     return permap == p.permap;
   }
@@ -115,22 +110,23 @@ public:
   {
     permap.print();
   }
-  void apply(const IntSequence &src, IntSequence &tar) const;
-  void apply(IntSequence &tar) const;
+  void apply(const IntSequence& src, IntSequence& tar) const;
+  void apply(IntSequence& tar) const;
   void inverse();
   int tailIdentity() const;
-  const IntSequence &
+  const IntSequence&
   getMap() const
   {
     return permap;
   }
-  IntSequence &
+  IntSequence&
   getMap()
   {
     return permap;
   }
+
 protected:
-  void computeSortingMap(const IntSequence &s);
+  void computeSortingMap(const IntSequence& s);
 };
 
 /* The PermutationSet maintains an array of of all permutations. The default
@@ -145,23 +141,24 @@ protected:
 
 class PermutationSet
 {
-  int order{1};
-  int size{1};
+  int order {1};
+  int size {1};
   std::vector<Permutation> pers;
+
 public:
   PermutationSet();
-  PermutationSet(const PermutationSet &ps, int n);
+  PermutationSet(const PermutationSet& ps, int n);
   int
   getNum() const
   {
     return size;
   }
-  const Permutation &
+  const Permutation&
   get(int i) const
   {
     return pers[i];
   }
-  std::vector<Permutation> getPreserving(const IntSequence &s) const;
+  std::vector<Permutation> getPreserving(const IntSequence& s) const;
 };
 
 /* The permutation bundle encapsulates all permutations sets up to some
@@ -170,9 +167,10 @@ public:
 class PermutationBundle
 {
   std::vector<PermutationSet> bundle;
+
 public:
   PermutationBundle(int nmax);
-  const PermutationSet &get(int n) const;
+  const PermutationSet& get(int n) const;
   void generateUpTo(int nmax);
 };
 
diff --git a/mex/sources/libkorder/tl/ps_tensor.cc b/mex/sources/libkorder/tl/ps_tensor.cc
index 5c1322cd7ee1295f50968de1d90302bb5b709750..21cb90ae33f77a5f3085d1bd5da4992dc59cc791 100644
--- a/mex/sources/libkorder/tl/ps_tensor.cc
+++ b/mex/sources/libkorder/tl/ps_tensor.cc
@@ -20,9 +20,9 @@
 
 #include "ps_tensor.hh"
 #include "fs_tensor.hh"
+#include "stack_container.hh"
 #include "tl_exception.hh"
 #include "tl_static.hh"
-#include "stack_container.hh"
 
 #include <iostream>
 
@@ -32,7 +32,7 @@
    1%, the second can be 3 times quicker. */
 
 UPSTensor::fill_method
-UPSTensor::decideFillMethod(const FSSparseTensor &t)
+UPSTensor::decideFillMethod(const FSSparseTensor& t)
 {
   if (t.getFillFactor() > 0.08)
     return fill_method::first;
@@ -42,16 +42,14 @@ UPSTensor::decideFillMethod(const FSSparseTensor &t)
 
 /* Here we make a slice. We decide what fill method to use and set it. */
 
-UPSTensor::UPSTensor(const FSSparseTensor &t, const IntSequence &ss,
-                     const IntSequence &coor, PerTensorDimens ptd)
-  : UTensor(indor::along_col, ptd.getNVX(),
-            t.nrows(), ptd.calcUnfoldMaxOffset(), ptd.dimen()),
+UPSTensor::UPSTensor(const FSSparseTensor& t, const IntSequence& ss, const IntSequence& coor,
+                     PerTensorDimens ptd) :
+    UTensor(indor::along_col, ptd.getNVX(), t.nrows(), ptd.calcUnfoldMaxOffset(), ptd.dimen()),
     tdims(std::move(ptd))
 {
   TL_RAISE_IF(coor.size() != t.dimen(),
               "Wrong coordinates length of stacks for UPSTensor slicing constructor");
-  TL_RAISE_IF(ss.sum() != t.nvar(),
-              "Wrong length of stacks for UPSTensor slicing constructor");
+  TL_RAISE_IF(ss.sum() != t.nvar(), "Wrong length of stacks for UPSTensor slicing constructor");
 
   if (decideFillMethod(t) == fill_method::first)
     fillFromSparseOne(t, ss, coor);
@@ -60,19 +58,17 @@ UPSTensor::UPSTensor(const FSSparseTensor &t, const IntSequence &ss,
 }
 
 void
-UPSTensor::increment(IntSequence &v) const
+UPSTensor::increment(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input/output vector size in UPSTensor::increment");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input/output vector size in UPSTensor::increment");
 
   UTensor::increment(v, tdims.getNVX());
 }
 
 void
-UPSTensor::decrement(IntSequence &v) const
+UPSTensor::decrement(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input/output vector size in UPSTensor::decrement");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input/output vector size in UPSTensor::decrement");
 
   UTensor::decrement(v, tdims.getNVX());
 }
@@ -84,19 +80,17 @@ UPSTensor::fold() const
 }
 
 int
-UPSTensor::getOffset(const IntSequence &v) const
+UPSTensor::getOffset(const IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input vector size in UPSTensor::getOffset");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input vector size in UPSTensor::getOffset");
 
   return UTensor::getOffset(v, tdims.getNVX());
 }
 
 void
-UPSTensor::addTo(FGSTensor &out) const
+UPSTensor::addTo(FGSTensor& out) const
 {
-  TL_RAISE_IF(out.getDims() != tdims,
-              "Tensors have incompatible dimens in UPSTensor::addTo");
+  TL_RAISE_IF(out.getDims() != tdims, "Tensors have incompatible dimens in UPSTensor::addTo");
   for (index in = out.begin(); in != out.end(); ++in)
     {
       IntSequence vtmp(dimen());
@@ -130,15 +124,14 @@ UPSTensor::addTo(FGSTensor &out) const
    construct submatrices, add them, and increment ‘outrun’. */
 
 void
-UPSTensor::addTo(UGSTensor &out) const
+UPSTensor::addTo(UGSTensor& out) const
 {
-  TL_RAISE_IF(out.getDims() != tdims,
-              "Tensors have incompatible dimens in UPSTensor::addTo");
+  TL_RAISE_IF(out.getDims() != tdims, "Tensors have incompatible dimens in UPSTensor::addTo");
   int cols = tailIdentitySize();
   int off = tdims.tailIdentity();
   IntSequence outrun(out.dimen(), 0);
-  IntSequence outrun_part(outrun, 0, out.dimen()-off);
-  IntSequence nvmax_part(out.getDims().getNVX(), 0, out.dimen()-off);
+  IntSequence outrun_part(outrun, 0, out.dimen() - off);
+  IntSequence nvmax_part(out.getDims().getNVX(), 0, out.dimen() - off);
   for (int out_col = 0; out_col < out.ncols(); out_col += cols)
     {
       // permute ‘outrun’
@@ -161,7 +154,7 @@ UPSTensor::addTo(UGSTensor &out) const
 int
 UPSTensor::tailIdentitySize() const
 {
-  return tdims.getNVX().mult(dimen()-tdims.tailIdentity(), dimen());
+  return tdims.getNVX().mult(dimen() - tdims.tailIdentity(), dimen());
 }
 
 /* This fill method is pretty dumb. We go through all columns in ‘this’
@@ -171,13 +164,13 @@ UPSTensor::tailIdentitySize() const
    really sparse tensors. */
 
 void
-UPSTensor::fillFromSparseOne(const FSSparseTensor &t, const IntSequence &ss,
-                             const IntSequence &coor)
+UPSTensor::fillFromSparseOne(const FSSparseTensor& t, const IntSequence& ss,
+                             const IntSequence& coor)
 {
   IntSequence cumtmp(ss.size());
   cumtmp[0] = 0;
   for (int i = 1; i < ss.size(); i++)
-    cumtmp[i] = cumtmp[i-1] + ss[i-1];
+    cumtmp[i] = cumtmp[i - 1] + ss[i - 1];
   IntSequence cum(coor.size());
   for (int i = 0; i < coor.size(); i++)
     cum[i] = cumtmp[coor[i]];
@@ -212,15 +205,15 @@ UPSTensor::fillFromSparseOne(const FSSparseTensor &t, const IntSequence &ss,
    item of the sparse tensor to the appropriate column. */
 
 void
-UPSTensor::fillFromSparseTwo(const FSSparseTensor &t, const IntSequence &ss,
-                             const IntSequence &coor)
+UPSTensor::fillFromSparseTwo(const FSSparseTensor& t, const IntSequence& ss,
+                             const IntSequence& coor)
 {
   IntSequence coor_srt(coor);
   coor_srt.sort();
   IntSequence cum(ss.size());
   cum[0] = 0;
   for (int i = 1; i < ss.size(); i++)
-    cum[i] = cum[i-1] + ss[i-1];
+    cum[i] = cum[i - 1] + ss[i - 1];
   IntSequence lb_srt(coor.size());
   IntSequence ub_srt(coor.size());
   for (int i = 0; i < coor.size(); i++)
@@ -229,7 +222,7 @@ UPSTensor::fillFromSparseTwo(const FSSparseTensor &t, const IntSequence &ss,
       ub_srt[i] = cum[coor_srt[i]] + ss[coor_srt[i]] - 1;
     }
 
-  const PermutationSet &pset = TLStatic::getPerm(coor.size());
+  const PermutationSet& pset = TLStatic::getPerm(coor.size());
   std::vector<Permutation> pp = pset.getPreserving(coor);
 
   Permutation unsort(coor);
@@ -242,7 +235,7 @@ UPSTensor::fillFromSparseTwo(const FSSparseTensor &t, const IntSequence &ss,
         IntSequence c(run->first);
         c.add(-1, lb_srt);
         unsort.apply(c);
-        for (auto &i : pp)
+        for (auto& i : pp)
           {
             IntSequence cp(coor.size());
             i.apply(c, cp);
@@ -260,7 +253,7 @@ UPSTensor::fillFromSparseTwo(const FSSparseTensor &t, const IntSequence &ss,
 void
 PerTensorDimens2::setDimensionSizes()
 {
-  const IntSequence &nvs = getNVS();
+  const IntSequence& nvs = getNVS();
   for (int i = 0; i < numSyms(); i++)
     {
       TensorDimens td(syms[i], nvs);
@@ -276,7 +269,7 @@ PerTensorDimens2::setDimensionSizes()
    code does. */
 
 int
-PerTensorDimens2::calcOffset(const IntSequence &coor) const
+PerTensorDimens2::calcOffset(const IntSequence& coor) const
 {
   TL_RAISE_IF(coor.size() != dimen(),
               "Wrong length of coordinates in PerTensorDimens2::calcOffset");
@@ -286,9 +279,9 @@ PerTensorDimens2::calcOffset(const IntSequence &coor) const
   for (int i = 0; i < numSyms(); i++)
     {
       TensorDimens td(syms[i], getNVS());
-      IntSequence c(cc, off, off+syms[i].dimen());
+      IntSequence c(cc, off, off + syms[i].dimen());
       int a = td.calcFoldOffset(c);
-      ret = ret*ds[i] + a;
+      ret = ret * ds[i] + a;
       off += syms[i].dimen();
     }
   return ret;
@@ -312,22 +305,21 @@ PerTensorDimens2::print() const
    the subsequences with respect to the symmetries of each dimension. */
 
 void
-FPSTensor::increment(IntSequence &v) const
+FPSTensor::increment(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong length of coordinates in FPSTensor::increment");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong length of coordinates in FPSTensor::increment");
   UTensor::increment(v, tdims.getNVX());
   int off = 0;
   for (int i = 0; i < tdims.numSyms(); i++)
     {
-      IntSequence c(v, off, off+tdims.getSym(i).dimen());
+      IntSequence c(v, off, off + tdims.getSym(i).dimen());
       c.pmonotone(tdims.getSym(i));
       off += tdims.getSym(i).dimen();
     }
 }
 
 void
-FPSTensor::decrement([[maybe_unused]] IntSequence &v) const
+FPSTensor::decrement([[maybe_unused]] IntSequence& v) const
 {
   TL_RAISE("FPSTensor::decrement not implemented");
 }
@@ -341,7 +333,7 @@ FPSTensor::unfold() const
 /* We only call calcOffset() on the PerTensorDimens2. */
 
 int
-FPSTensor::getOffset(const IntSequence &v) const
+FPSTensor::getOffset(const IntSequence& v) const
 {
   return tdims.calcOffset(v);
 }
@@ -353,7 +345,7 @@ FPSTensor::getOffset(const IntSequence &v) const
    folded). */
 
 void
-FPSTensor::addTo(FGSTensor &out) const
+FPSTensor::addTo(FGSTensor& out) const
 {
   for (index tar = out.begin(); tar != out.end(); ++tar)
     {
@@ -384,10 +376,10 @@ FPSTensor::addTo(FGSTensor &out) const
    Kronecker product of the rows, and go through all of items with the
    coordinates, and add to appropriate rows of ‘this’ tensor. */
 
-FPSTensor::FPSTensor(const TensorDimens &td, const Equivalence &e, const Permutation &p,
-                     const GSSparseTensor &a, const KronProdAll &kp)
-  : FTensor(indor::along_col, PerTensorDimens(td, Permutation(e, p)).getNVX(),
-            a.nrows(), kp.ncols(), td.dimen()),
+FPSTensor::FPSTensor(const TensorDimens& td, const Equivalence& e, const Permutation& p,
+                     const GSSparseTensor& a, const KronProdAll& kp) :
+    FTensor(indor::along_col, PerTensorDimens(td, Permutation(e, p)).getNVX(), a.nrows(),
+            kp.ncols(), td.dimen()),
     tdims(td, e, p)
 {
   zeros();
@@ -396,7 +388,7 @@ FPSTensor::FPSTensor(const TensorDimens &td, const Equivalence &e, const Permuta
   for (Tensor::index run = dummy.begin(); run != dummy.end(); ++run)
     {
       Tensor::index fold_ind = dummy.getFirstIndexOf(run);
-      const IntSequence &c = fold_ind.getCoor();
+      const IntSequence& c = fold_ind.getCoor();
       auto sl = a.getMap().lower_bound(c);
       if (sl != a.getMap().end())
         {
@@ -404,7 +396,7 @@ FPSTensor::FPSTensor(const TensorDimens &td, const Equivalence &e, const Permuta
           auto su = a.getMap().upper_bound(c);
           for (auto srun = sl; srun != su; ++srun)
             {
-              Vector out_row{getRow(srun->second.first)};
+              Vector out_row {getRow(srun->second.first)};
               out_row.add(srun->second.second, *row_prod);
             }
         }
diff --git a/mex/sources/libkorder/tl/ps_tensor.hh b/mex/sources/libkorder/tl/ps_tensor.hh
index e981f31a8d221cc83012dab4dfef9d4f47086c35..0fa037108707e30f2a68c04d46d771cc3cc09fec 100644
--- a/mex/sources/libkorder/tl/ps_tensor.hh
+++ b/mex/sources/libkorder/tl/ps_tensor.hh
@@ -57,12 +57,12 @@
 #ifndef PS_TENSOR_H
 #define PS_TENSOR_H
 
-#include "tensor.hh"
-#include "gs_tensor.hh"
 #include "equivalence.hh"
-#include "permutation.hh"
+#include "gs_tensor.hh"
 #include "kron_prod.hh"
+#include "permutation.hh"
 #include "sparse_tensor.hh"
+#include "tensor.hh"
 
 /* Here we declare a class describing dimensions of permuted symmetry tensor.
    It inherits from TensorDimens and adds a permutation which permutes ‘nvmax’.
@@ -92,31 +92,31 @@ private:
     s.sort();
     return s;
   }
+
 protected:
   Permutation per;
+
 public:
-  PerTensorDimens(Symmetry s, IntSequence nvars, const Equivalence &e)
-    : TensorDimens(std::move(s), std::move(nvars)), per(e)
+  PerTensorDimens(Symmetry s, IntSequence nvars, const Equivalence& e) :
+      TensorDimens(std::move(s), std::move(nvars)), per(e)
   {
     per.apply(nvmax);
   }
-  PerTensorDimens(TensorDimens td, const Equivalence &e)
-    : TensorDimens(std::move(td)), per(e)
+  PerTensorDimens(TensorDimens td, const Equivalence& e) : TensorDimens(std::move(td)), per(e)
   {
     per.apply(nvmax);
   }
-  PerTensorDimens(TensorDimens td, Permutation p)
-    : TensorDimens(std::move(td)), per(std::move(p))
+  PerTensorDimens(TensorDimens td, Permutation p) : TensorDimens(std::move(td)), per(std::move(p))
   {
     per.apply(nvmax);
   }
-  PerTensorDimens(IntSequence ss, IntSequence coor)
-    : TensorDimens(std::move(ss), sortIntSequence(coor)), per(std::move(coor))
+  PerTensorDimens(IntSequence ss, IntSequence coor) :
+      TensorDimens(std::move(ss), sortIntSequence(coor)), per(std::move(coor))
   {
     per.apply(nvmax);
   }
   bool
-  operator==(const PerTensorDimens &td) const
+  operator==(const PerTensorDimens& td) const
   {
     return TensorDimens::operator==(td) && per == td.per;
   }
@@ -125,7 +125,7 @@ public:
   {
     return per.tailIdentity();
   }
-  const Permutation &
+  const Permutation&
   getPer() const
   {
     return per;
@@ -158,6 +158,7 @@ public:
 class UPSTensor : public UTensor
 {
   const PerTensorDimens tdims;
+
 public:
   // UPSTensor constructors from Kronecker product
   /* Here we have four constructors making an UPSTensor from a product
@@ -165,10 +166,9 @@ public:
 
   /* Constructs the tensor from equivalence classes of the given equivalence in
      an order given by the equivalence */
-  UPSTensor(TensorDimens td, const Equivalence &e,
-            const ConstTwoDMatrix &a, const KronProdAll &kp)
-    : UTensor(indor::along_col, PerTensorDimens(td, e).getNVX(),
-              a.nrows(), kp.ncols(), td.dimen()),
+  UPSTensor(TensorDimens td, const Equivalence& e, const ConstTwoDMatrix& a,
+            const KronProdAll& kp) :
+      UTensor(indor::along_col, PerTensorDimens(td, e).getNVX(), a.nrows(), kp.ncols(), td.dimen()),
       tdims(std::move(td), e)
   {
     kp.mult(a, *this);
@@ -177,9 +177,9 @@ public:
   /* Same as the previous one but with optimized KronProdAllOptim, which has a
      different order of matrices than given by the classes in the equivalence.
      This permutation is projected to the permutation of the UPSTensor. */
-  UPSTensor(TensorDimens td, const Equivalence &e,
-            const ConstTwoDMatrix &a, const KronProdAllOptim &kp)
-    : UTensor(indor::along_col, PerTensorDimens(td, Permutation(e, kp.getPer())).getNVX(),
+  UPSTensor(TensorDimens td, const Equivalence& e, const ConstTwoDMatrix& a,
+            const KronProdAllOptim& kp) :
+      UTensor(indor::along_col, PerTensorDimens(td, Permutation(e, kp.getPer())).getNVX(),
               a.nrows(), kp.ncols(), td.dimen()),
       tdims(std::move(td), Permutation(e, kp.getPer()))
   {
@@ -188,10 +188,10 @@ public:
 
   /* Same as the first constructor, but the classes of the equivalence are
      permuted by the given permutation. */
-  UPSTensor(TensorDimens td, const Equivalence &e, const Permutation &p,
-            const ConstTwoDMatrix &a, const KronProdAll &kp)
-    : UTensor(indor::along_col, PerTensorDimens(td, Permutation(e, p)).getNVX(),
-              a.nrows(), kp.ncols(), td.dimen()),
+  UPSTensor(TensorDimens td, const Equivalence& e, const Permutation& p, const ConstTwoDMatrix& a,
+            const KronProdAll& kp) :
+      UTensor(indor::along_col, PerTensorDimens(td, Permutation(e, p)).getNVX(), a.nrows(),
+              kp.ncols(), td.dimen()),
       tdims(std::move(td), Permutation(e, p))
   {
     kp.mult(a, *this);
@@ -200,36 +200,40 @@ public:
   /* Most general constructor. It allows for a permutation of equivalence
      classes, and for optimized KronProdAllOptim, which permutes the permuted
      equivalence classes. */
-  UPSTensor(TensorDimens td, const Equivalence &e, const Permutation &p,
-            const ConstTwoDMatrix &a, const KronProdAllOptim &kp)
-    : UTensor(indor::along_col, PerTensorDimens(td, Permutation(e, Permutation(p, kp.getPer()))).getNVX(),
-              a.nrows(), kp.ncols(), td.dimen()),
+  UPSTensor(TensorDimens td, const Equivalence& e, const Permutation& p, const ConstTwoDMatrix& a,
+            const KronProdAllOptim& kp) :
+      UTensor(indor::along_col,
+              PerTensorDimens(td, Permutation(e, Permutation(p, kp.getPer()))).getNVX(), a.nrows(),
+              kp.ncols(), td.dimen()),
       tdims(std::move(td), Permutation(e, Permutation(p, kp.getPer())))
   {
     kp.mult(a, *this);
   }
 
-  UPSTensor(const FSSparseTensor &t, const IntSequence &ss,
-            const IntSequence &coor, PerTensorDimens ptd);
-  UPSTensor(const UPSTensor &) = default;
-  UPSTensor(UPSTensor &&) = default;
+  UPSTensor(const FSSparseTensor& t, const IntSequence& ss, const IntSequence& coor,
+            PerTensorDimens ptd);
+  UPSTensor(const UPSTensor&) = default;
+  UPSTensor(UPSTensor&&) = default;
 
-  void increment(IntSequence &v) const override;
-  void decrement(IntSequence &v) const override;
+  void increment(IntSequence& v) const override;
+  void decrement(IntSequence& v) const override;
   std::unique_ptr<FTensor> fold() const override;
 
-  int getOffset(const IntSequence &v) const override;
-  void addTo(FGSTensor &out) const;
-  void addTo(UGSTensor &out) const;
+  int getOffset(const IntSequence& v) const override;
+  void addTo(FGSTensor& out) const;
+  void addTo(UGSTensor& out) const;
+
+  enum class fill_method
+  {
+    first,
+    second
+  };
+  static fill_method decideFillMethod(const FSSparseTensor& t);
 
-  enum class fill_method { first, second };
-  static fill_method decideFillMethod(const FSSparseTensor &t);
 private:
   int tailIdentitySize() const;
-  void fillFromSparseOne(const FSSparseTensor &t, const IntSequence &ss,
-                         const IntSequence &coor);
-  void fillFromSparseTwo(const FSSparseTensor &t, const IntSequence &ss,
-                         const IntSequence &coor);
+  void fillFromSparseOne(const FSSparseTensor& t, const IntSequence& ss, const IntSequence& coor);
+  void fillFromSparseTwo(const FSSparseTensor& t, const IntSequence& ss, const IntSequence& coor);
 };
 
 /* Here we define an abstraction for the tensor dimension with the symmetry
@@ -250,19 +254,15 @@ class PerTensorDimens2 : public PerTensorDimens
 {
   InducedSymmetries syms;
   IntSequence ds;
+
 public:
-  PerTensorDimens2(const TensorDimens &td, const Equivalence &e,
-                   const Permutation &p)
-    : PerTensorDimens(td, Permutation(e, p)),
-      syms(e, p, td.getSym()),
-      ds(syms.size())
+  PerTensorDimens2(const TensorDimens& td, const Equivalence& e, const Permutation& p) :
+      PerTensorDimens(td, Permutation(e, p)), syms(e, p, td.getSym()), ds(syms.size())
   {
     setDimensionSizes();
   }
-  PerTensorDimens2(const TensorDimens &td, const Equivalence &e)
-    : PerTensorDimens(td, e),
-      syms(e, td.getSym()),
-      ds(syms.size())
+  PerTensorDimens2(const TensorDimens& td, const Equivalence& e) :
+      PerTensorDimens(td, e), syms(e, td.getSym()), ds(syms.size())
   {
     setDimensionSizes();
   }
@@ -271,7 +271,7 @@ public:
   {
     return static_cast<int>(syms.size());
   }
-  const Symmetry &
+  const Symmetry&
   getSym(int i) const
   {
     return syms[i];
@@ -281,8 +281,9 @@ public:
   {
     return ds.mult();
   }
-  int calcOffset(const IntSequence &coor) const;
+  int calcOffset(const IntSequence& coor) const;
   void print() const;
+
 protected:
   void setDimensionSizes();
 };
@@ -299,7 +300,7 @@ protected:
       ⎝     y    ⎠
    we get for one concrete equivalence:
 
-    [F_x⁴y³u³v²] = … + [f_g²h²x²y]·([g]_xv ⊗ [g]_u²v ⊗ [h]_xu ⊗ [h]_y² ⊗ 
+    [F_x⁴y³u³v²] = … + [f_g²h²x²y]·([g]_xv ⊗ [g]_u²v ⊗ [h]_xu ⊗ [h]_y² ⊗
                                     [I]_x ⊗ [I]_x ⊗ [I]_y)
                      + …
 
@@ -326,6 +327,7 @@ class StackProduct;
 class FPSTensor : public FTensor
 {
   const PerTensorDimens2 tdims;
+
 public:
   /* As for UPSTensor, we provide four constructors allowing for
      combinations of permuting equivalence classes, and optimization of
@@ -335,51 +337,51 @@ public:
      constructors, we have one constructor multiplying with general
      symmetry sparse tensor (coming as a sparse slice of the full symmetry
      sparse tensor). */
-  FPSTensor(const TensorDimens &td, const Equivalence &e,
-            const ConstTwoDMatrix &a, const KronProdAll &kp)
-    : FTensor(indor::along_col, PerTensorDimens(td, e).getNVX(),
-              a.nrows(), kp.ncols(), td.dimen()),
+  FPSTensor(const TensorDimens& td, const Equivalence& e, const ConstTwoDMatrix& a,
+            const KronProdAll& kp) :
+      FTensor(indor::along_col, PerTensorDimens(td, e).getNVX(), a.nrows(), kp.ncols(), td.dimen()),
       tdims(td, e)
   {
     kp.mult(a, *this);
   }
-  FPSTensor(const TensorDimens &td, const Equivalence &e,
-            const ConstTwoDMatrix &a, const KronProdAllOptim &kp)
-    : FTensor(indor::along_col, PerTensorDimens(td, Permutation(e, kp.getPer())).getNVX(),
+  FPSTensor(const TensorDimens& td, const Equivalence& e, const ConstTwoDMatrix& a,
+            const KronProdAllOptim& kp) :
+      FTensor(indor::along_col, PerTensorDimens(td, Permutation(e, kp.getPer())).getNVX(),
               a.nrows(), kp.ncols(), td.dimen()),
       tdims(td, e, kp.getPer())
   {
     kp.mult(a, *this);
   }
-  FPSTensor(const TensorDimens &td, const Equivalence &e, const Permutation &p,
-            const ConstTwoDMatrix &a, const KronProdAll &kp)
-    : FTensor(indor::along_col, PerTensorDimens(td, Permutation(e, p)).getNVX(),
-              a.nrows(), kp.ncols(), td.dimen()),
+  FPSTensor(const TensorDimens& td, const Equivalence& e, const Permutation& p,
+            const ConstTwoDMatrix& a, const KronProdAll& kp) :
+      FTensor(indor::along_col, PerTensorDimens(td, Permutation(e, p)).getNVX(), a.nrows(),
+              kp.ncols(), td.dimen()),
       tdims(td, e, p)
   {
     kp.mult(a, *this);
   }
-  FPSTensor(const TensorDimens &td, const Equivalence &e, const Permutation &p,
-            const ConstTwoDMatrix &a, const KronProdAllOptim &kp)
-    : FTensor(indor::along_col, PerTensorDimens(td, Permutation(e, Permutation(p, kp.getPer()))).getNVX(),
-              a.nrows(), kp.ncols(), td.dimen()),
+  FPSTensor(const TensorDimens& td, const Equivalence& e, const Permutation& p,
+            const ConstTwoDMatrix& a, const KronProdAllOptim& kp) :
+      FTensor(indor::along_col,
+              PerTensorDimens(td, Permutation(e, Permutation(p, kp.getPer()))).getNVX(), a.nrows(),
+              kp.ncols(), td.dimen()),
       tdims(td, e, Permutation(p, kp.getPer()))
   {
     kp.mult(a, *this);
   }
 
-  FPSTensor(const TensorDimens &td, const Equivalence &e, const Permutation &p,
-            const GSSparseTensor &t, const KronProdAll &kp);
+  FPSTensor(const TensorDimens& td, const Equivalence& e, const Permutation& p,
+            const GSSparseTensor& t, const KronProdAll& kp);
 
-  FPSTensor(const FPSTensor &) = default;
-  FPSTensor(FPSTensor &&) = default;
+  FPSTensor(const FPSTensor&) = default;
+  FPSTensor(FPSTensor&&) = default;
 
-  void increment(IntSequence &v) const override;
-  void decrement(IntSequence &v) const override;
+  void increment(IntSequence& v) const override;
+  void decrement(IntSequence& v) const override;
   std::unique_ptr<UTensor> unfold() const override;
 
-  int getOffset(const IntSequence &v) const override;
-  void addTo(FGSTensor &out) const;
+  int getOffset(const IntSequence& v) const override;
+  void addTo(FGSTensor& out) const;
 };
 
 #endif
diff --git a/mex/sources/libkorder/tl/pyramid_prod.cc b/mex/sources/libkorder/tl/pyramid_prod.cc
index 140d230840ba797e3b73da78512f5b38182af90b..a71978cb6827c0f8125d0c0446c366ad36ab5ebe 100644
--- a/mex/sources/libkorder/tl/pyramid_prod.cc
+++ b/mex/sources/libkorder/tl/pyramid_prod.cc
@@ -33,22 +33,18 @@
    permutation and add the Kronecker product of the selected columns. This is
    done by addKronColumn(). */
 
-USubTensor::USubTensor(const TensorDimens &bdims,
-                       const TensorDimens &hdims,
-                       const FGSContainer &cont,
-                       const std::vector<IntSequence> &lst)
-  : URTensor(lst.size(), hdims.getNVX(0), hdims.dimen())
+USubTensor::USubTensor(const TensorDimens& bdims, const TensorDimens& hdims,
+                       const FGSContainer& cont, const std::vector<IntSequence>& lst) :
+    URTensor(lst.size(), hdims.getNVX(0), hdims.dimen())
 {
-  TL_RAISE_IF(!hdims.getNVX().isConstant(),
-              "Tensor has not full symmetry in USubTensor()");
-  const EquivalenceSet &eset = TLStatic::getEquiv(bdims.dimen());
+  TL_RAISE_IF(!hdims.getNVX().isConstant(), "Tensor has not full symmetry in USubTensor()");
+  const EquivalenceSet& eset = TLStatic::getEquiv(bdims.dimen());
   zeros();
-  for (const auto &it : eset)
+  for (const auto& it : eset)
     if (it.numClasses() == hdims.dimen())
       {
         Permutation per(it);
-        std::vector<const FGSTensor *> ts
-          = cont.fetchTensors(bdims.getSym(), it);
+        std::vector<const FGSTensor*> ts = cont.fetchTensors(bdims.getSym(), it);
         for (int i = 0; i < static_cast<int>(lst.size()); i++)
           {
             IntSequence perindex(lst[i].size());
@@ -72,20 +68,19 @@ USubTensor::USubTensor(const TensorDimens &bdims,
    of URSingleTensor to the i-th column. */
 
 void
-USubTensor::addKronColumn(int i, const std::vector<const FGSTensor *> &ts,
-                          const IntSequence &pindex)
+USubTensor::addKronColumn(int i, const std::vector<const FGSTensor*>& ts, const IntSequence& pindex)
 {
   std::vector<ConstVector> tmpcols;
   int lastdim = 0;
   for (auto t : ts)
     {
-      IntSequence ind(pindex, lastdim, lastdim+t->dimen());
+      IntSequence ind(pindex, lastdim, lastdim + t->dimen());
       lastdim += t->dimen();
       index in(*t, ind);
       tmpcols.push_back(t->getCol(*in));
     }
 
   URSingleTensor kronmult(tmpcols);
-  Vector coli{getCol(i)};
+  Vector coli {getCol(i)};
   coli.add(1.0, kronmult.getData());
 }
diff --git a/mex/sources/libkorder/tl/pyramid_prod.hh b/mex/sources/libkorder/tl/pyramid_prod.hh
index d6d29fae1c53d5dfea418704b9b54d11dd4ed138..1372e3ef93cca1d0d3d124fc914ac13023840362 100644
--- a/mex/sources/libkorder/tl/pyramid_prod.hh
+++ b/mex/sources/libkorder/tl/pyramid_prod.hh
@@ -69,9 +69,9 @@
 #ifndef PYRAMID_PROD_H
 #define PYRAMID_PROD_H
 
+#include "gs_tensor.hh"
 #include "int_sequence.hh"
 #include "rfs_tensor.hh"
-#include "gs_tensor.hh"
 #include "t_container.hh"
 
 #include <vector>
@@ -84,10 +84,9 @@
 class USubTensor : public URTensor
 {
 public:
-  USubTensor(const TensorDimens &bdims, const TensorDimens &hdims,
-             const FGSContainer &cont, const std::vector<IntSequence> &lst);
-  void addKronColumn(int i, const std::vector<const FGSTensor *> &ts,
-                     const IntSequence &pindex);
+  USubTensor(const TensorDimens& bdims, const TensorDimens& hdims, const FGSContainer& cont,
+             const std::vector<IntSequence>& lst);
+  void addKronColumn(int i, const std::vector<const FGSTensor*>& ts, const IntSequence& pindex);
 };
 
 #endif
diff --git a/mex/sources/libkorder/tl/pyramid_prod2.cc b/mex/sources/libkorder/tl/pyramid_prod2.cc
index 9ffdab74dfe9902f42ba51bae710b1cda03e4594..d4f6bb32a7398979cef313a3ed76b72816bdc495 100644
--- a/mex/sources/libkorder/tl/pyramid_prod2.cc
+++ b/mex/sources/libkorder/tl/pyramid_prod2.cc
@@ -25,18 +25,15 @@
    fills ‘cols’ and ‘unit_flag’ for the given column ‘c’. Then we set
    ‘end_seq’ according to ‘unit_flag’ and columns lengths. */
 
-IrregTensorHeader::IrregTensorHeader(const StackProduct<FGSTensor> &sp,
-                                     const IntSequence &c)
-  : nv(sp.getAllSize()),
-    unit_flag(sp.dimen()),
-    cols(sp.createPackedColumns(c, unit_flag)),
+IrregTensorHeader::IrregTensorHeader(const StackProduct<FGSTensor>& sp, const IntSequence& c) :
+    nv(sp.getAllSize()), unit_flag(sp.dimen()), cols(sp.createPackedColumns(c, unit_flag)),
     end_seq(sp.dimen())
 {
   for (int i = 0; i < sp.dimen(); i++)
     {
       end_seq[i] = cols[i]->length();
       if (unit_flag[i] != -1)
-        end_seq[i] = unit_flag[i]+1;
+        end_seq[i] = unit_flag[i] + 1;
     }
 }
 
@@ -45,21 +42,20 @@ IrregTensorHeader::IrregTensorHeader(const StackProduct<FGSTensor> &sp,
    difference is how we increment item of coordinates. */
 
 void
-IrregTensorHeader::increment(IntSequence &v) const
+IrregTensorHeader::increment(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong size of coordinates in IrregTensorHeader::increment");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong size of coordinates in IrregTensorHeader::increment");
 
   if (v.size() == 0)
     return;
-  int i = v.size()-1;
+  int i = v.size() - 1;
 
   // increment i-th item in coordinate ‘v’
   /* Here we increment item of coordinates. Whenever we reached end of
      column coming from matrices, and ‘unit_flag’ is not -1, we have to
      jump to that ‘unit_flag’. */
   v[i]++;
-  if (unit_flag[i] != -1 && v[i] == cols[i]->length()-1)
+  if (unit_flag[i] != -1 && v[i] == cols[i]->length() - 1)
     v[i] = unit_flag[i];
 
   while (i > 0 && v[i] == end_seq[i])
@@ -69,7 +65,7 @@ IrregTensorHeader::increment(IntSequence &v) const
       // increment i-th item in coordinate ‘v’
       /* Same code as above */
       v[i]++;
-      if (unit_flag[i] != -1 && v[i] == cols[i]->length()-1)
+      if (unit_flag[i] != -1 && v[i] == cols[i]->length() - 1)
         v[i] = unit_flag[i];
     }
 }
@@ -88,9 +84,8 @@ IrregTensorHeader::calcMaxOffset() const
 /* Everything is done in IrregTensorHeader, only we have to Kronecker
    multiply all columns of the header. */
 
-IrregTensor::IrregTensor(const IrregTensorHeader &h)
-  : Tensor(indor::along_row, IntSequence(h.dimen(), 0), h.end_seq,
-           h.calcMaxOffset(), 1, h.dimen()),
+IrregTensor::IrregTensor(const IrregTensorHeader& h) :
+    Tensor(indor::along_row, IntSequence(h.dimen(), 0), h.end_seq, h.calcMaxOffset(), 1, h.dimen()),
     header(h)
 {
   if (header.dimen() == 1)
@@ -99,20 +94,18 @@ IrregTensor::IrregTensor(const IrregTensorHeader &h)
       return;
     }
 
-  auto last = std::make_unique<Vector>(*(header.cols[header.dimen()-1]));
-  for (int i = header.dimen()-2; i > 0; i--)
+  auto last = std::make_unique<Vector>(*(header.cols[header.dimen() - 1]));
+  for (int i = header.dimen() - 2; i > 0; i--)
     {
-      auto newlast = std::make_unique<Vector>(last->length()*header.cols[i]->length());
-      KronProd::kronMult(ConstVector(*(header.cols[i])),
-                         ConstVector(*last), *newlast);
+      auto newlast = std::make_unique<Vector>(last->length() * header.cols[i]->length());
+      KronProd::kronMult(ConstVector(*(header.cols[i])), ConstVector(*last), *newlast);
       last = std::move(newlast);
     }
-  KronProd::kronMult(ConstVector(*(header.cols[0])),
-                     ConstVector(*last), getData());
+  KronProd::kronMult(ConstVector(*(header.cols[0])), ConstVector(*last), getData());
 }
 
 void
-IrregTensor::addTo(FRSingleTensor &out) const
+IrregTensor::addTo(FRSingleTensor& out) const
 {
   for (index it = begin(); it != end(); ++it)
     {
diff --git a/mex/sources/libkorder/tl/pyramid_prod2.hh b/mex/sources/libkorder/tl/pyramid_prod2.hh
index f20085c92133dec688d1044608731723814df32b..129ec783b2fd2933544f8945fa597ed8d7998b54 100644
--- a/mex/sources/libkorder/tl/pyramid_prod2.hh
+++ b/mex/sources/libkorder/tl/pyramid_prod2.hh
@@ -45,8 +45,8 @@
 
    which can be written as:
 
-    ⎛[v_yu]_α₁β₁⎞ ⎛[v_y]_α₂⎞ ⎛[vᵤᵤ]_β₂β₃⎞ 
-    ⎢[w_yu]_α₁β₁⎥ ⎢[w_y]_α₂⎥ ⎢[wᵤᵤ]_β₂β₃⎥       
+    ⎛[v_yu]_α₁β₁⎞ ⎛[v_y]_α₂⎞ ⎛[vᵤᵤ]_β₂β₃⎞
+    ⎢[w_yu]_α₁β₁⎥ ⎢[w_y]_α₂⎥ ⎢[wᵤᵤ]_β₂β₃⎥
     ⎢     0     ⎥⊗⎢  1_α₂  ⎥⊗⎢     0    ⎥
     ⎝     0     ⎠ ⎝    0   ⎠ ⎝     0    ⎠
    where 1_α₂ is a column of zeros having the only 1 at α₂ index.
@@ -59,7 +59,7 @@
                   ⎛[v_y]_α₂⎞
    ⎛[v_yu]_α₁β₁⎞⊗ ⎢[w_y]_α₂⎥⊗⎛[vᵤᵤ]_β₂β₃⎞
    ⎝[w_yu]_α₁β₁⎠  ⎝    1   ⎠ ⎝[wᵤᵤ]_β₂β₃⎠
-  
+
    The class will have a tensor infrastructure introducing ‘index’ which
    iterates over all items in the column with γ₁γ₂γ₃
    as coordinates in [f_z³]. The data of such a tensor is
@@ -71,10 +71,10 @@
 #define PYRAMID_PROD2_H
 
 #include "permutation.hh"
-#include "tensor.hh"
-#include "tl_exception.hh"
 #include "rfs_tensor.hh"
 #include "stack_container.hh"
+#include "tensor.hh"
+#include "tl_exception.hh"
 
 #include "Vector.hh"
 
@@ -103,14 +103,15 @@ class IrregTensorHeader
   IntSequence unit_flag;
   std::vector<std::unique_ptr<Vector>> cols;
   IntSequence end_seq;
+
 public:
-  IrregTensorHeader(const StackProduct<FGSTensor> &sp, const IntSequence &c);
+  IrregTensorHeader(const StackProduct<FGSTensor>& sp, const IntSequence& c);
   int
   dimen() const
   {
     return unit_flag.size();
   }
-  void increment(IntSequence &v) const;
+  void increment(IntSequence& v) const;
   int calcMaxOffset() const;
 };
 
@@ -131,22 +132,23 @@ public:
 
 class IrregTensor : public Tensor
 {
-  const IrregTensorHeader &header;
+  const IrregTensorHeader& header;
+
 public:
-  IrregTensor(const IrregTensorHeader &h);
-  void addTo(FRSingleTensor &out) const;
+  IrregTensor(const IrregTensorHeader& h);
+  void addTo(FRSingleTensor& out) const;
   void
-  increment(IntSequence &v) const override
+  increment(IntSequence& v) const override
   {
     header.increment(v);
   }
   void
-  decrement([[maybe_unused]] IntSequence &v) const override
+  decrement([[maybe_unused]] IntSequence& v) const override
   {
     TL_RAISE("Not implemented error in IrregTensor::decrement");
   }
   int
-  getOffset([[maybe_unused]] const IntSequence &v) const override
+  getOffset([[maybe_unused]] const IntSequence& v) const override
   {
     TL_RAISE("Not implemented error in IrregTensor::getOffset");
   }
diff --git a/mex/sources/libkorder/tl/rfs_tensor.cc b/mex/sources/libkorder/tl/rfs_tensor.cc
index a22efe85ff871cd82232265c7bf82e086710e497..4bf66428f52ad7e2995f0ba05b2bfe666ec5769a 100644
--- a/mex/sources/libkorder/tl/rfs_tensor.cc
+++ b/mex/sources/libkorder/tl/rfs_tensor.cc
@@ -26,10 +26,9 @@
    corresponding to one folded index. So we go through all the rows in the
    unfolded tensor ‘ut’, make an index of the folded tensor by sorting the
    coordinates, and add the row. */
-FRTensor::FRTensor(const URTensor &ut)
-  : FTensor(indor::along_row, IntSequence(ut.dimen(), ut.nvar()),
-            FFSTensor::calcMaxOffset(ut.nvar(), ut.dimen()), ut.ncols(),
-            ut.dimen()),
+FRTensor::FRTensor(const URTensor& ut) :
+    FTensor(indor::along_row, IntSequence(ut.dimen(), ut.nvar()),
+            FFSTensor::calcMaxOffset(ut.nvar(), ut.dimen()), ut.ncols(), ut.dimen()),
     nv(ut.nvar())
 {
   zeros();
@@ -51,20 +50,18 @@ FRTensor::unfold() const
 /* Incrementing is easy. The same as for FFSTensor. */
 
 void
-FRTensor::increment(IntSequence &v) const
+FRTensor::increment(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input/output vector size in FRTensor::increment");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input/output vector size in FRTensor::increment");
 
   UTensor::increment(v, nv);
   v.monotone();
 }
 
 void
-FRTensor::decrement(IntSequence &v) const
+FRTensor::decrement(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input/output vector size in FRTensor::decrement");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input/output vector size in FRTensor::decrement");
 
   FTensor::decrement(v, nv);
 }
@@ -73,10 +70,9 @@ FRTensor::decrement(IntSequence &v) const
    columns of folded tensor to unfolded and leave other columns
    (duplicates) zero. In this way, if the unfolded tensor is folded back,
    we should get the same data. */
-URTensor::URTensor(const FRTensor &ft)
-  : UTensor(indor::along_row, IntSequence(ft.dimen(), ft.nvar()),
-            UFSTensor::calcMaxOffset(ft.nvar(), ft.dimen()), ft.ncols(),
-            ft.dimen()),
+URTensor::URTensor(const FRTensor& ft) :
+    UTensor(indor::along_row, IntSequence(ft.dimen(), ft.nvar()),
+            UFSTensor::calcMaxOffset(ft.nvar(), ft.dimen()), ft.ncols(), ft.dimen()),
     nv(ft.nvar())
 {
   zeros();
@@ -94,28 +90,25 @@ URTensor::fold() const
 }
 
 void
-URTensor::increment(IntSequence &v) const
+URTensor::increment(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input/output vector size in URTensor::increment");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input/output vector size in URTensor::increment");
 
   UTensor::increment(v, nv);
 }
 
 void
-URTensor::decrement(IntSequence &v) const
+URTensor::decrement(IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input/output vector size in URTensor::decrement");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input/output vector size in URTensor::decrement");
 
   UTensor::decrement(v, nv);
 }
 
 int
-URTensor::getOffset(const IntSequence &v) const
+URTensor::getOffset(const IntSequence& v) const
 {
-  TL_RAISE_IF(v.size() != dimen(),
-              "Wrong input vector size in URTensor::getOffset");
+  TL_RAISE_IF(v.size() != dimen(), "Wrong input vector size in URTensor::getOffset");
 
   return UTensor::getOffset(v, nv);
 }
@@ -123,8 +116,8 @@ URTensor::getOffset(const IntSequence &v) const
 /* Here we construct v₁⊗v₂⊗…⊗vₙ, where v₁,v₂,…,vₙ are stored in a
    std::vector<ConstVector>. */
 
-URSingleTensor::URSingleTensor(const std::vector<ConstVector> &cols)
-  : URTensor(1, cols[0].length(), cols.size())
+URSingleTensor::URSingleTensor(const std::vector<ConstVector>& cols) :
+    URTensor(1, cols[0].length(), cols.size())
 {
   if (dimen() == 1)
     {
@@ -132,10 +125,10 @@ URSingleTensor::URSingleTensor(const std::vector<ConstVector> &cols)
       return;
     }
 
-  auto last = std::make_unique<Vector>(cols[cols.size()-1]);
-  for (int i = cols.size()-2; i > 0; i--)
+  auto last = std::make_unique<Vector>(cols[cols.size() - 1]);
+  for (int i = cols.size() - 2; i > 0; i--)
     {
-      auto newlast = std::make_unique<Vector>(power(nvar(), cols.size()-i));
+      auto newlast = std::make_unique<Vector>(power(nvar(), cols.size() - i));
       KronProd::kronMult(cols[i], ConstVector(*last), *newlast);
       last = std::move(newlast);
     }
@@ -144,8 +137,7 @@ URSingleTensor::URSingleTensor(const std::vector<ConstVector> &cols)
 
 /* Here we construct v⊗…⊗v, where ‘d’ gives the number of copies of v. */
 
-URSingleTensor::URSingleTensor(const ConstVector &v, int d)
-  : URTensor(1, v.length(), d)
+URSingleTensor::URSingleTensor(const ConstVector& v, int d) : URTensor(1, v.length(), d)
 {
   if (d == 1)
     {
@@ -154,9 +146,9 @@ URSingleTensor::URSingleTensor(const ConstVector &v, int d)
     }
 
   auto last = std::make_unique<Vector>(v);
-  for (int i = d-2; i > 0; i--)
+  for (int i = d - 2; i > 0; i--)
     {
-      auto newlast = std::make_unique<Vector>(last->length()*v.length());
+      auto newlast = std::make_unique<Vector>(last->length() * v.length());
       KronProd::kronMult(v, ConstVector(*last), *newlast);
       last = std::move(newlast);
     }
@@ -172,8 +164,7 @@ URSingleTensor::fold() const
 /* The conversion from unfolded URSingleTensor to folded FRSingleTensor is
    exactly the same as the conversion from URTensor to FRTensor, except that we
    do not copy rows but elements. */
-FRSingleTensor::FRSingleTensor(const URSingleTensor &ut)
-  : FRTensor(1, ut.nvar(), ut.dimen())
+FRSingleTensor::FRSingleTensor(const URSingleTensor& ut) : FRTensor(1, ut.nvar(), ut.dimen())
 {
   zeros();
   for (index in = ut.begin(); in != ut.end(); ++in)
diff --git a/mex/sources/libkorder/tl/rfs_tensor.hh b/mex/sources/libkorder/tl/rfs_tensor.hh
index 5c7bbc2c2d1704cbc7771ee93e83e86f0f76eaaa..bd47c9e847b1bfb58afc68069cc3c7bd401a1902 100644
--- a/mex/sources/libkorder/tl/rfs_tensor.hh
+++ b/mex/sources/libkorder/tl/rfs_tensor.hh
@@ -55,9 +55,9 @@
 #ifndef RFS_TENSOR_H
 #define RFS_TENSOR_H
 
-#include "tensor.hh"
 #include "fs_tensor.hh"
 #include "symmetry.hh"
+#include "tensor.hh"
 
 /* This is straightforward and very similar to UFSTensor. */
 
@@ -65,23 +65,24 @@ class FRTensor;
 class URTensor : public UTensor
 {
   int nv;
+
 public:
-  URTensor(int c, int nvar, int d)
-    : UTensor(indor::along_row, IntSequence(d, nvar),
-              UFSTensor::calcMaxOffset(nvar, d), c, d), nv(nvar)
+  URTensor(int c, int nvar, int d) :
+      UTensor(indor::along_row, IntSequence(d, nvar), UFSTensor::calcMaxOffset(nvar, d), c, d),
+      nv(nvar)
   {
   }
-  URTensor(const URTensor &) = default;
-  URTensor(URTensor &&) = default;
-  explicit URTensor(const FRTensor &ft);
+  URTensor(const URTensor&) = default;
+  URTensor(URTensor&&) = default;
+  explicit URTensor(const FRTensor& ft);
 
   ~URTensor() override = default;
 
-  void increment(IntSequence &v) const override;
-  void decrement(IntSequence &v) const override;
+  void increment(IntSequence& v) const override;
+  void decrement(IntSequence& v) const override;
   std::unique_ptr<FTensor> fold() const override;
 
-  int getOffset(const IntSequence &v) const override;
+  int getOffset(const IntSequence& v) const override;
   int
   nvar() const
   {
@@ -90,7 +91,7 @@ public:
   Symmetry
   getSym() const
   {
-    return Symmetry{dimen()};
+    return Symmetry {dimen()};
   }
 };
 
@@ -99,20 +100,21 @@ public:
 class FRTensor : public FTensor
 {
   int nv;
+
 public:
-  FRTensor(int c, int nvar, int d)
-    : FTensor(indor::along_row, IntSequence(d, nvar),
-              FFSTensor::calcMaxOffset(nvar, d), c, d), nv(nvar)
+  FRTensor(int c, int nvar, int d) :
+      FTensor(indor::along_row, IntSequence(d, nvar), FFSTensor::calcMaxOffset(nvar, d), c, d),
+      nv(nvar)
   {
   }
-  FRTensor(const FRTensor &) = default;
-  FRTensor(FRTensor &&) = default;
-  explicit FRTensor(const URTensor &ut);
+  FRTensor(const FRTensor&) = default;
+  FRTensor(FRTensor&&) = default;
+  explicit FRTensor(const URTensor& ut);
 
   ~FRTensor() override = default;
 
-  void increment(IntSequence &v) const override;
-  void decrement(IntSequence &v) const override;
+  void increment(IntSequence& v) const override;
+  void decrement(IntSequence& v) const override;
   std::unique_ptr<UTensor> unfold() const override;
 
   int
@@ -121,14 +123,14 @@ public:
     return nv;
   }
   int
-  getOffset(const IntSequence &v) const override
+  getOffset(const IntSequence& v) const override
   {
     return FTensor::getOffset(v, nv);
   }
   Symmetry
   getSym() const
   {
-    return Symmetry{dimen()};
+    return Symmetry {dimen()};
   }
 };
 
@@ -141,14 +143,13 @@ public:
 class URSingleTensor : public URTensor
 {
 public:
-  URSingleTensor(int nvar, int d)
-    : URTensor(1, nvar, d)
+  URSingleTensor(int nvar, int d) : URTensor(1, nvar, d)
   {
   }
-  URSingleTensor(const std::vector<ConstVector> &cols);
-  URSingleTensor(const ConstVector &v, int d);
-  URSingleTensor(const URSingleTensor &) = default;
-  URSingleTensor(URSingleTensor &&) = default;
+  URSingleTensor(const std::vector<ConstVector>& cols);
+  URSingleTensor(const ConstVector& v, int d);
+  URSingleTensor(const URSingleTensor&) = default;
+  URSingleTensor(URSingleTensor&&) = default;
   ~URSingleTensor() override = default;
   std::unique_ptr<FTensor> fold() const override;
 };
@@ -161,13 +162,12 @@ public:
 class FRSingleTensor : public FRTensor
 {
 public:
-  FRSingleTensor(int nvar, int d)
-    : FRTensor(1, nvar, d)
+  FRSingleTensor(int nvar, int d) : FRTensor(1, nvar, d)
   {
   }
-  explicit FRSingleTensor(const URSingleTensor &ut);
-  FRSingleTensor(const FRSingleTensor &) = default;
-  FRSingleTensor(FRSingleTensor &&) = default;
+  explicit FRSingleTensor(const URSingleTensor& ut);
+  FRSingleTensor(const FRSingleTensor&) = default;
+  FRSingleTensor(FRSingleTensor&&) = default;
   ~FRSingleTensor() override = default;
 };
 
diff --git a/mex/sources/libkorder/tl/sparse_tensor.cc b/mex/sources/libkorder/tl/sparse_tensor.cc
index d92aebc7c4161c9d8def9bb3c9d8341c0ab9c51e..f8930f12bef0ef7696e842e36108ead4d848ce30 100644
--- a/mex/sources/libkorder/tl/sparse_tensor.cc
+++ b/mex/sources/libkorder/tl/sparse_tensor.cc
@@ -22,9 +22,9 @@
 #include "fs_tensor.hh"
 #include "tl_exception.hh"
 
-#include <iostream>
-#include <iomanip>
 #include <cmath>
+#include <iomanip>
+#include <iostream>
 
 /* This is straightforward. Before we insert anything, we do a few
    checks. Then we reset ‘first_nz_row’ and ‘last_nz_row’ if necessary. */
@@ -32,12 +32,9 @@
 void
 SparseTensor::insert(IntSequence key, int r, double c)
 {
-  TL_RAISE_IF(r < 0 || r >= nr,
-              "Row number out of dimension of tensor in SparseTensor::insert");
-  TL_RAISE_IF(key.size() != dimen(),
-              "Wrong length of key in SparseTensor::insert");
-  TL_RAISE_IF(!std::isfinite(c),
-              "Insertion of non-finite value in SparseTensor::insert");
+  TL_RAISE_IF(r < 0 || r >= nr, "Row number out of dimension of tensor in SparseTensor::insert");
+  TL_RAISE_IF(key.size() != dimen(), "Wrong length of key in SparseTensor::insert");
+  TL_RAISE_IF(!std::isfinite(c), "Insertion of non-finite value in SparseTensor::insert");
 
   auto first_pos = m.lower_bound(key);
 
@@ -80,11 +77,11 @@ SparseTensor::getFoldIndexFillFactor() const
   while (start_col != m.end())
     {
       cnt++;
-      const IntSequence &key = start_col->first;
+      const IntSequence& key = start_col->first;
       start_col = m.upper_bound(key);
     }
 
-  return static_cast<double>(cnt)/ncols();
+  return static_cast<double>(cnt) / ncols();
 }
 
 /* This returns a ratio of a number of non-zero columns in unfolded
@@ -97,12 +94,12 @@ SparseTensor::getUnfoldIndexFillFactor() const
   auto start_col = m.begin();
   while (start_col != m.end())
     {
-      const IntSequence &key = start_col->first;
+      const IntSequence& key = start_col->first;
       cnt += key.getSymmetry().noverseq();
       start_col = m.upper_bound(key);
     }
 
-  return static_cast<double>(cnt)/ncols();
+  return static_cast<double>(cnt) / ncols();
 }
 
 /* This prints the fill factor and all items. */
@@ -110,13 +107,12 @@ SparseTensor::getUnfoldIndexFillFactor() const
 void
 SparseTensor::print() const
 {
-  std::cout << "Fill: "
-            << std::fixed << std::setprecision(2) << 100*getFillFactor()
+  std::cout << "Fill: " << std::fixed << std::setprecision(2) << 100 * getFillFactor()
             << std::setprecision(6) << std::defaultfloat << " %\n";
   auto start_col = m.begin();
   while (start_col != m.end())
     {
-      const IntSequence &key = start_col->first;
+      const IntSequence& key = start_col->first;
       std::cout << "Column: ";
       key.print();
       auto end_col = m.upper_bound(key);
@@ -132,18 +128,16 @@ SparseTensor::print() const
     }
 }
 
-FSSparseTensor::FSSparseTensor(int d, int nvar, int r)
-  : SparseTensor(d, r, FFSTensor::calcMaxOffset(nvar, d)),
-    nv(nvar), sym{d}
+FSSparseTensor::FSSparseTensor(int d, int nvar, int r) :
+    SparseTensor(d, r, FFSTensor::calcMaxOffset(nvar, d)), nv(nvar), sym {d}
 {
 }
 
 void
 FSSparseTensor::insert(IntSequence key, int r, double c)
 {
-  TL_RAISE_IF(!key.isSorted(),
-              "Key is not sorted in FSSparseTensor::insert");
-  TL_RAISE_IF(key[key.size()-1] >= nv || key[0] < 0,
+  TL_RAISE_IF(!key.isSorted(), "Key is not sorted in FSSparseTensor::insert");
+  TL_RAISE_IF(key[key.size() - 1] >= nv || key[0] < 0,
               "Wrong value of the key in FSSparseTensor::insert");
   SparseTensor::insert(std::move(key), r, c);
 }
@@ -163,7 +157,7 @@ FSSparseTensor::insert(IntSequence key, int r, double c)
    everything depends how filled is the sparse tensor. */
 
 void
-FSSparseTensor::multColumnAndAdd(const Tensor &t, Vector &v) const
+FSSparseTensor::multColumnAndAdd(const Tensor& t, Vector& v) const
 {
   // check compatibility of input parameters
   TL_RAISE_IF(v.length() != nrows(),
@@ -183,7 +177,7 @@ FSSparseTensor::multColumnAndAdd(const Tensor &t, Vector &v) const
           key.sort();
 
           // check that ‘key’ is within the range
-          TL_RAISE_IF(key[0] < 0 || key[key.size()-1] >= nv,
+          TL_RAISE_IF(key[0] < 0 || key[key.size() - 1] >= nv,
                       "Wrong coordinates of index in FSSparseTensor::multColumnAndAdd");
 
           auto first_pos = m.lower_bound(key);
@@ -201,15 +195,16 @@ FSSparseTensor::multColumnAndAdd(const Tensor &t, Vector &v) const
 void
 FSSparseTensor::print() const
 {
-  std::cout << "FS Sparse tensor: dim=" << dim << ", nv=" << nv << ", (" << nr << 'x' << nc << ")\n";
+  std::cout << "FS Sparse tensor: dim=" << dim << ", nv=" << nv << ", (" << nr << 'x' << nc
+            << ")\n";
   SparseTensor::print();
 }
 
 // GSSparseTensor slicing constructor
 /* This is the same as FGSTensor slicing constructor from FSSparseTensor. */
-GSSparseTensor::GSSparseTensor(const FSSparseTensor &t, const IntSequence &ss,
-                               const IntSequence &coor, TensorDimens td)
-  : SparseTensor(td.dimen(), t.nrows(), td.calcFoldMaxOffset()),
+GSSparseTensor::GSSparseTensor(const FSSparseTensor& t, const IntSequence& ss,
+                               const IntSequence& coor, TensorDimens td) :
+    SparseTensor(td.dimen(), t.nrows(), td.calcFoldMaxOffset()),
     tdims(std::move(td))
 {
   // set ‘lb’ and ‘ub’ to lower and upper bounds of slice indices
@@ -217,7 +212,7 @@ GSSparseTensor::GSSparseTensor(const FSSparseTensor &t, const IntSequence &ss,
      details. */
   IntSequence s_offsets(ss.size(), 0);
   for (int i = 1; i < ss.size(); i++)
-    s_offsets[i] = s_offsets[i-1] + ss[i-1];
+    s_offsets[i] = s_offsets[i - 1] + ss[i - 1];
 
   IntSequence lb(coor.size());
   IntSequence ub(coor.size());
@@ -241,8 +236,7 @@ GSSparseTensor::GSSparseTensor(const FSSparseTensor &t, const IntSequence &ss,
 void
 GSSparseTensor::insert(IntSequence s, int r, double c)
 {
-  TL_RAISE_IF(!s.less(tdims.getNVX()),
-              "Wrong coordinates of index in GSSparseTensor::insert");
+  TL_RAISE_IF(!s.less(tdims.getNVX()), "Wrong coordinates of index in GSSparseTensor::insert");
   SparseTensor::insert(std::move(s), r, c);
 }
 
diff --git a/mex/sources/libkorder/tl/sparse_tensor.hh b/mex/sources/libkorder/tl/sparse_tensor.hh
index 68547eb565a8f5594e6de6dccf9c6342466a0301..071ba99fffbd7cbfd55b98c4f52f7d856a705853 100644
--- a/mex/sources/libkorder/tl/sparse_tensor.hh
+++ b/mex/sources/libkorder/tl/sparse_tensor.hh
@@ -42,17 +42,17 @@
 #ifndef SPARSE_TENSOR_H
 #define SPARSE_TENSOR_H
 
+#include "Vector.hh"
+#include "gs_tensor.hh"
 #include "symmetry.hh"
 #include "tensor.hh"
-#include "gs_tensor.hh"
-#include "Vector.hh"
 
 #include <map>
 
 struct ltseq
 {
   bool
-  operator()(const IntSequence &s1, const IntSequence &s2) const
+  operator()(const IntSequence& s1, const IntSequence& s2) const
   {
     return s1 < s2;
   }
@@ -66,6 +66,7 @@ class SparseTensor
 {
 public:
   using Map = std::multimap<IntSequence, std::pair<int, double>, ltseq>;
+
 protected:
   Map m;
   int dim;
@@ -73,13 +74,14 @@ protected:
   int nc;
   int first_nz_row;
   int last_nz_row;
+
 public:
-  SparseTensor(int d, int nnr, int nnc)
-    : dim(d), nr(nnr), nc(nnc), first_nz_row(nr), last_nz_row(-1)
+  SparseTensor(int d, int nnr, int nnc) :
+      dim(d), nr(nnr), nc(nnc), first_nz_row(nr), last_nz_row(-1)
   {
   }
   void insert(IntSequence s, int r, double c);
-  const Map &
+  const Map&
   getMap() const
   {
     return m;
@@ -102,7 +104,7 @@ public:
   double
   getFillFactor() const
   {
-    return static_cast<double>(m.size())/nrows()/ncols();
+    return static_cast<double>(m.size()) / nrows() / ncols();
   }
   double getFoldIndexFillFactor() const;
   double getUnfoldIndexFillFactor() const;
@@ -121,7 +123,7 @@ public:
   {
     return last_nz_row;
   }
-  virtual const Symmetry &getSym() const = 0;
+  virtual const Symmetry& getSym() const = 0;
   void print() const;
   bool isFinite() const;
 };
@@ -135,11 +137,12 @@ class FSSparseTensor : public SparseTensor
 private:
   int nv;
   Symmetry sym;
+
 public:
   FSSparseTensor(int d, int nvar, int r);
   void insert(IntSequence s, int r, double c);
-  void multColumnAndAdd(const Tensor &t, Vector &v) const;
-  const Symmetry &
+  void multColumnAndAdd(const Tensor& t, Vector& v) const;
+  const Symmetry&
   getSym() const override
   {
     return sym;
@@ -161,22 +164,22 @@ class GSSparseTensor : public SparseTensor
 {
 private:
   TensorDimens tdims;
+
 public:
-  GSSparseTensor(const FSSparseTensor &t, const IntSequence &ss,
-                 const IntSequence &coor, TensorDimens td);
+  GSSparseTensor(const FSSparseTensor& t, const IntSequence& ss, const IntSequence& coor,
+                 TensorDimens td);
   void insert(IntSequence s, int r, double c);
-  const Symmetry &
+  const Symmetry&
   getSym() const override
   {
     return tdims.getSym();
   }
-  const TensorDimens &
+  const TensorDimens&
   getDims() const
   {
     return tdims;
   }
   void print() const;
-
 };
 
 #endif
diff --git a/mex/sources/libkorder/tl/stack_container.cc b/mex/sources/libkorder/tl/stack_container.cc
index f773045a1fa69e060883f42e2125de0859494254..220ed8db087bb794f4b3a47a0e0d0fbc4f4a9e44 100644
--- a/mex/sources/libkorder/tl/stack_container.cc
+++ b/mex/sources/libkorder/tl/stack_container.cc
@@ -19,8 +19,8 @@
  */
 
 #include "stack_container.hh"
-#include "pyramid_prod2.hh"
 #include "ps_tensor.hh"
+#include "pyramid_prod2.hh"
 
 #include <memory>
 
@@ -36,8 +36,7 @@
    preliminary examination shows that multAndAddSparse2() is the best in terms
    of time. */
 void
-FoldedStackContainer::multAndAdd(const FSSparseTensor &t,
-                                 FGSTensor &out) const
+FoldedStackContainer::multAndAdd(const FSSparseTensor& t, FGSTensor& out) const
 {
   TL_RAISE_IF(t.nvar() != getAllSize(),
               "Wrong number of variables of tensor for FoldedStackContainer::multAndAdd");
@@ -50,14 +49,14 @@ FoldedStackContainer::multAndAdd(const FSSparseTensor &t,
    of general symmetric tensors. The implementation is pretty the same as
    UnfoldedStackContainer::multAndAdd() dense code. */
 void
-FoldedStackContainer::multAndAdd(int dim, const FGSContainer &c, FGSTensor &out) const
+FoldedStackContainer::multAndAdd(int dim, const FGSContainer& c, FGSTensor& out) const
 {
   TL_RAISE_IF(c.num() != numStacks(),
               "Wrong symmetry length of container for FoldedStackContainer::multAndAdd");
 
   sthread::detach_thread_group gr;
 
-  for (auto &si : SymmetrySet(dim, c.num()))
+  for (auto& si : SymmetrySet(dim, c.num()))
     if (c.check(si))
       gr.insert(std::make_unique<WorkerFoldMAADense>(*this, si, c, out));
 
@@ -67,26 +66,24 @@ FoldedStackContainer::multAndAdd(int dim, const FGSContainer &c, FGSTensor &out)
 /* This is analogous to WorkerUnfoldMAADense::operator()() code. */
 
 void
-WorkerFoldMAADense::operator()(std::mutex &mut)
+WorkerFoldMAADense::operator()(std::mutex& mut)
 {
   Permutation iden(dense_cont.num());
   IntSequence coor(iden.getMap().unfold(sym));
-  const FGSTensor &g = dense_cont.get(sym);
+  const FGSTensor& g = dense_cont.get(sym);
   cont.multAndAddStacks(coor, g, out, mut);
 }
 
-WorkerFoldMAADense::WorkerFoldMAADense(const FoldedStackContainer &container,
-                                       Symmetry s,
-                                       const FGSContainer &dcontainer,
-                                       FGSTensor &outten)
-  : cont(container), sym(std::move(s)), dense_cont(dcontainer), out(outten)
+WorkerFoldMAADense::WorkerFoldMAADense(const FoldedStackContainer& container, Symmetry s,
+                                       const FGSContainer& dcontainer, FGSTensor& outten) :
+    cont(container),
+    sym(std::move(s)), dense_cont(dcontainer), out(outten)
 {
 }
 
 /* This is analogous to UnfoldedStackContainer::multAndAddSparse1() code. */
 void
-FoldedStackContainer::multAndAddSparse1(const FSSparseTensor &t,
-                                        FGSTensor &out) const
+FoldedStackContainer::multAndAddSparse1(const FSSparseTensor& t, FGSTensor& out) const
 {
   sthread::detach_thread_group gr;
   UFSTensor dummy(0, numStacks(), t.dimen());
@@ -106,20 +103,19 @@ FoldedStackContainer::multAndAddSparse1(const FSSparseTensor &t,
    vertically narrow out accordingly. */
 
 void
-WorkerFoldMAASparse1::operator()(std::mutex &mut)
+WorkerFoldMAASparse1::operator()(std::mutex& mut)
 {
-  const EquivalenceSet &eset = TLStatic::getEquiv(out.dimen());
-  const PermutationSet &pset = TLStatic::getPerm(t.dimen());
+  const EquivalenceSet& eset = TLStatic::getEquiv(out.dimen());
+  const PermutationSet& pset = TLStatic::getPerm(t.dimen());
   Permutation iden(t.dimen());
 
-  UPSTensor slice(t, cont.getStackSizes(), coor,
-                  PerTensorDimens(cont.getStackSizes(), coor));
+  UPSTensor slice(t, cont.getStackSizes(), coor, PerTensorDimens(cont.getStackSizes(), coor));
   for (int iper = 0; iper < pset.getNum(); iper++)
     {
-      const Permutation &per = pset.get(iper);
+      const Permutation& per = pset.get(iper);
       IntSequence percoor(coor.size());
       per.apply(coor, percoor);
-      for (const auto &it : eset)
+      for (const auto& it : eset)
         if (it.numClasses() == t.dimen())
           {
             StackProduct<FGSTensor> sp(cont, it, out.getSym());
@@ -127,12 +123,12 @@ WorkerFoldMAASparse1::operator()(std::mutex &mut)
               {
                 KronProdStack<FGSTensor> kp(sp, percoor);
                 kp.optimizeOrder();
-                const Permutation &oper = kp.getPer();
+                const Permutation& oper = kp.getPer();
                 if (Permutation(oper, per) == iden)
                   {
                     FPSTensor fps(out.getDims(), it, slice, kp);
                     {
-                      std::unique_lock<std::mutex> lk{mut};
+                      std::unique_lock<std::mutex> lk {mut};
                       fps.addTo(out);
                     }
                   }
@@ -141,10 +137,11 @@ WorkerFoldMAASparse1::operator()(std::mutex &mut)
     }
 }
 
-WorkerFoldMAASparse1::WorkerFoldMAASparse1(const FoldedStackContainer &container,
-                                           const FSSparseTensor &ten,
-                                           FGSTensor &outten, IntSequence c)
-  : cont(container), t(ten), out(outten), coor(std::move(c))
+WorkerFoldMAASparse1::WorkerFoldMAASparse1(const FoldedStackContainer& container,
+                                           const FSSparseTensor& ten, FGSTensor& outten,
+                                           IntSequence c) :
+    cont(container),
+    t(ten), out(outten), coor(std::move(c))
 {
 }
 
@@ -155,8 +152,7 @@ WorkerFoldMAASparse1::WorkerFoldMAASparse1(const FoldedStackContainer &container
    multiplies all the combinations compatible with the slice. */
 
 void
-FoldedStackContainer::multAndAddSparse2(const FSSparseTensor &t,
-                                        FGSTensor &out) const
+FoldedStackContainer::multAndAddSparse2(const FSSparseTensor& t, FGSTensor& out) const
 {
   sthread::detach_thread_group gr;
   FFSTensor dummy_f(0, numStacks(), t.dimen());
@@ -178,10 +174,9 @@ FoldedStackContainer::multAndAddSparse2(const FSSparseTensor &t,
    rows. */
 
 void
-WorkerFoldMAASparse2::operator()(std::mutex &mut)
+WorkerFoldMAASparse2::operator()(std::mutex& mut)
 {
-  GSSparseTensor slice(t, cont.getStackSizes(), coor,
-                       TensorDimens(cont.getStackSizes(), coor));
+  GSSparseTensor slice(t, cont.getStackSizes(), coor, TensorDimens(cont.getStackSizes(), coor));
   if (slice.getNumNonZero())
     {
       if (slice.getUnfoldIndexFillFactor() > FoldedStackContainer::fill_threshold)
@@ -189,8 +184,8 @@ WorkerFoldMAASparse2::operator()(std::mutex &mut)
           FGSTensor dense_slice(slice);
           int r1 = slice.getFirstNonZeroRow();
           int r2 = slice.getLastNonZeroRow();
-          FGSTensor dense_slice1(r1, r2-r1+1, dense_slice);
-          FGSTensor out1(r1, r2-r1+1, out);
+          FGSTensor dense_slice1(r1, r2 - r1 + 1, dense_slice);
+          FGSTensor out1(r1, r2 - r1 + 1, out);
           cont.multAndAddStacks(coor, dense_slice1, out1, mut);
         }
       else
@@ -198,10 +193,11 @@ WorkerFoldMAASparse2::operator()(std::mutex &mut)
     }
 }
 
-WorkerFoldMAASparse2::WorkerFoldMAASparse2(const FoldedStackContainer &container,
-                                           const FSSparseTensor &ten,
-                                           FGSTensor &outten, IntSequence c)
-  : cont(container), t(ten), out(outten), coor(std::move(c))
+WorkerFoldMAASparse2::WorkerFoldMAASparse2(const FoldedStackContainer& container,
+                                           const FSSparseTensor& ten, FGSTensor& outten,
+                                           IntSequence c) :
+    cont(container),
+    t(ten), out(outten), coor(std::move(c))
 {
 }
 
@@ -220,16 +216,15 @@ WorkerFoldMAASparse2::WorkerFoldMAASparse2(const FoldedStackContainer &container
    sparse tensor. */
 
 void
-FoldedStackContainer::multAndAddSparse3(const FSSparseTensor &t,
-                                        FGSTensor &out) const
+FoldedStackContainer::multAndAddSparse3(const FSSparseTensor& t, FGSTensor& out) const
 {
-  const EquivalenceSet &eset = TLStatic::getEquiv(out.dimen());
+  const EquivalenceSet& eset = TLStatic::getEquiv(out.dimen());
   for (Tensor::index run = out.begin(); run != out.end(); ++run)
     {
-      Vector outcol{out.getCol(*run)};
+      Vector outcol {out.getCol(*run)};
       FRSingleTensor sumcol(t.nvar(), t.dimen());
       sumcol.zeros();
-      for (const auto &it : eset)
+      for (const auto& it : eset)
         if (it.numClasses() == t.dimen())
           {
             StackProduct<FGSTensor> sp(*this, it, out.getSym());
@@ -250,7 +245,7 @@ FoldedStackContainer::multAndAddSparse3(const FSSparseTensor &t,
    FPSTensor| sparse constructor. */
 
 void
-FoldedStackContainer::multAndAddSparse4(const FSSparseTensor &t, FGSTensor &out) const
+FoldedStackContainer::multAndAddSparse4(const FSSparseTensor& t, FGSTensor& out) const
 {
   sthread::detach_thread_group gr;
   FFSTensor dummy_f(0, numStacks(), t.dimen());
@@ -265,18 +260,18 @@ FoldedStackContainer::multAndAddSparse4(const FSSparseTensor &t, FGSTensor &out)
    multAndAddStacks(). */
 
 void
-WorkerFoldMAASparse4::operator()(std::mutex &mut)
+WorkerFoldMAASparse4::operator()(std::mutex& mut)
 {
-  GSSparseTensor slice(t, cont.getStackSizes(), coor,
-                       TensorDimens(cont.getStackSizes(), coor));
+  GSSparseTensor slice(t, cont.getStackSizes(), coor, TensorDimens(cont.getStackSizes(), coor));
   if (slice.getNumNonZero())
     cont.multAndAddStacks(coor, slice, out, mut);
 }
 
-WorkerFoldMAASparse4::WorkerFoldMAASparse4(const FoldedStackContainer &container,
-                                           const FSSparseTensor &ten,
-                                           FGSTensor &outten, IntSequence c)
-  : cont(container), t(ten), out(outten), coor(std::move(c))
+WorkerFoldMAASparse4::WorkerFoldMAASparse4(const FoldedStackContainer& container,
+                                           const FSSparseTensor& ten, FGSTensor& outten,
+                                           IntSequence c) :
+    cont(container),
+    t(ten), out(outten), coor(std::move(c))
 {
 }
 
@@ -288,11 +283,10 @@ WorkerFoldMAASparse4::WorkerFoldMAASparse4(const FoldedStackContainer &container
    multiply with unfolded rows of Kronecker product. However, columns of such a
    product are partially folded giving a rise to the FPSTensor. */
 void
-FoldedStackContainer::multAndAddStacks(const IntSequence &coor,
-                                       const FGSTensor &g,
-                                       FGSTensor &out, std::mutex &mut) const
+FoldedStackContainer::multAndAddStacks(const IntSequence& coor, const FGSTensor& g, FGSTensor& out,
+                                       std::mutex& mut) const
 {
-  const EquivalenceSet &eset = TLStatic::getEquiv(out.dimen());
+  const EquivalenceSet& eset = TLStatic::getEquiv(out.dimen());
 
   UGSTensor ug(g);
   UFSTensor dummy_u(0, numStacks(), g.dimen());
@@ -304,7 +298,7 @@ FoldedStackContainer::multAndAddStacks(const IntSequence &coor,
         {
           Permutation sort_per(ui.getCoor());
           sort_per.inverse();
-          for (const auto &it : eset)
+          for (const auto& it : eset)
             if (it.numClasses() == g.dimen())
               {
                 StackProduct<FGSTensor> sp(*this, it, sort_per, out.getSym());
@@ -315,7 +309,7 @@ FoldedStackContainer::multAndAddStacks(const IntSequence &coor,
                       kp.optimizeOrder();
                     FPSTensor fps(out.getDims(), it, sort_per, ug, kp);
                     {
-                      std::unique_lock<std::mutex> lk{mut};
+                      std::unique_lock<std::mutex> lk {mut};
                       fps.addTo(out);
                     }
                   }
@@ -330,11 +324,10 @@ FoldedStackContainer::multAndAddStacks(const IntSequence &coor,
    with sparse slice GSSparseTensor (not dense slice FGSTensor). The
    multiplication is done in FPSTensor sparse constructor. */
 void
-FoldedStackContainer::multAndAddStacks(const IntSequence &coor,
-                                       const GSSparseTensor &g,
-                                       FGSTensor &out, std::mutex &mut) const
+FoldedStackContainer::multAndAddStacks(const IntSequence& coor, const GSSparseTensor& g,
+                                       FGSTensor& out, std::mutex& mut) const
 {
-  const EquivalenceSet &eset = TLStatic::getEquiv(out.dimen());
+  const EquivalenceSet& eset = TLStatic::getEquiv(out.dimen());
   UFSTensor dummy_u(0, numStacks(), g.dimen());
   for (Tensor::index ui = dummy_u.begin(); ui != dummy_u.end(); ++ui)
     {
@@ -344,7 +337,7 @@ FoldedStackContainer::multAndAddStacks(const IntSequence &coor,
         {
           Permutation sort_per(ui.getCoor());
           sort_per.inverse();
-          for (const auto &it : eset)
+          for (const auto& it : eset)
             if (it.numClasses() == g.dimen())
               {
                 StackProduct<FGSTensor> sp(*this, it, sort_per, out.getSym());
@@ -353,7 +346,7 @@ FoldedStackContainer::multAndAddStacks(const IntSequence &coor,
                     KronProdStack<FGSTensor> kp(sp, coor);
                     FPSTensor fps(out.getDims(), it, sort_per, g, kp);
                     {
-                      std::unique_lock<std::mutex> lk{mut};
+                      std::unique_lock<std::mutex> lk {mut};
                       fps.addTo(out);
                     }
                   }
@@ -367,8 +360,7 @@ FoldedStackContainer::multAndAddStacks(const IntSequence &coor,
     multAndAddSparse2(). The first one allows for optimization of
     Kronecker products, so it seems to be more efficient. */
 void
-UnfoldedStackContainer::multAndAdd(const FSSparseTensor &t,
-                                   UGSTensor &out) const
+UnfoldedStackContainer::multAndAdd(const FSSparseTensor& t, UGSTensor& out) const
 {
   TL_RAISE_IF(t.nvar() != getAllSize(),
               "Wrong number of variables of tensor for UnfoldedStackContainer::multAndAdd");
@@ -389,14 +381,13 @@ UnfoldedStackContainer::multAndAdd(const FSSparseTensor &t,
    reason of doing this is that we are unable to calculate symmetry from
    stack coordinates as easily as stack coordinates from the symmetry. */
 void
-UnfoldedStackContainer::multAndAdd(int dim, const UGSContainer &c,
-                                   UGSTensor &out) const
+UnfoldedStackContainer::multAndAdd(int dim, const UGSContainer& c, UGSTensor& out) const
 {
   TL_RAISE_IF(c.num() != numStacks(),
               "Wrong symmetry length of container for UnfoldedStackContainer::multAndAdd");
 
   sthread::detach_thread_group gr;
-  for (auto &si : SymmetrySet(dim, c.num()))
+  for (auto& si : SymmetrySet(dim, c.num()))
     if (c.check(si))
       gr.insert(std::make_unique<WorkerUnfoldMAADense>(*this, si, c, out));
 
@@ -404,19 +395,18 @@ UnfoldedStackContainer::multAndAdd(int dim, const UGSContainer &c,
 }
 
 void
-WorkerUnfoldMAADense::operator()(std::mutex &mut)
+WorkerUnfoldMAADense::operator()(std::mutex& mut)
 {
   Permutation iden(dense_cont.num());
   IntSequence coor(iden.getMap().unfold(sym));
-  const UGSTensor &g = dense_cont.get(sym);
+  const UGSTensor& g = dense_cont.get(sym);
   cont.multAndAddStacks(coor, g, out, mut);
 }
 
-WorkerUnfoldMAADense::WorkerUnfoldMAADense(const UnfoldedStackContainer &container,
-                                           Symmetry s,
-                                           const UGSContainer &dcontainer,
-                                           UGSTensor &outten)
-  : cont(container), sym(std::move(s)), dense_cont(dcontainer), out(outten)
+WorkerUnfoldMAADense::WorkerUnfoldMAADense(const UnfoldedStackContainer& container, Symmetry s,
+                                           const UGSContainer& dcontainer, UGSTensor& outten) :
+    cont(container),
+    sym(std::move(s)), dense_cont(dcontainer), out(outten)
 {
 }
 
@@ -435,8 +425,7 @@ WorkerUnfoldMAADense::WorkerUnfoldMAADense(const UnfoldedStackContainer &contain
    operation for the slice corresponding to the combination of the stacks. */
 
 void
-UnfoldedStackContainer::multAndAddSparse1(const FSSparseTensor &t,
-                                          UGSTensor &out) const
+UnfoldedStackContainer::multAndAddSparse1(const FSSparseTensor& t, UGSTensor& out) const
 {
   sthread::detach_thread_group gr;
   UFSTensor dummy(0, numStacks(), t.dimen());
@@ -470,20 +459,19 @@ UnfoldedStackContainer::multAndAddSparse1(const FSSparseTensor &t,
    TODO: vertically narrow slice and out according to the fill in t. */
 
 void
-WorkerUnfoldMAASparse1::operator()(std::mutex &mut)
+WorkerUnfoldMAASparse1::operator()(std::mutex& mut)
 {
-  const EquivalenceSet &eset = TLStatic::getEquiv(out.dimen());
-  const PermutationSet &pset = TLStatic::getPerm(t.dimen());
+  const EquivalenceSet& eset = TLStatic::getEquiv(out.dimen());
+  const PermutationSet& pset = TLStatic::getPerm(t.dimen());
   Permutation iden(t.dimen());
 
-  UPSTensor slice(t, cont.getStackSizes(), coor,
-                  PerTensorDimens(cont.getStackSizes(), coor));
+  UPSTensor slice(t, cont.getStackSizes(), coor, PerTensorDimens(cont.getStackSizes(), coor));
   for (int iper = 0; iper < pset.getNum(); iper++)
     {
-      const Permutation &per = pset.get(iper);
+      const Permutation& per = pset.get(iper);
       IntSequence percoor(coor.size());
       per.apply(coor, percoor);
-      for (const auto &it : eset)
+      for (const auto& it : eset)
         if (it.numClasses() == t.dimen())
           {
             StackProduct<UGSTensor> sp(cont, it, out.getSym());
@@ -491,12 +479,12 @@ WorkerUnfoldMAASparse1::operator()(std::mutex &mut)
               {
                 KronProdStack<UGSTensor> kp(sp, percoor);
                 kp.optimizeOrder();
-                const Permutation &oper = kp.getPer();
+                const Permutation& oper = kp.getPer();
                 if (Permutation(oper, per) == iden)
                   {
                     UPSTensor ups(out.getDims(), it, slice, kp);
                     {
-                      std::unique_lock<std::mutex> lk{mut};
+                      std::unique_lock<std::mutex> lk {mut};
                       ups.addTo(out);
                     }
                   }
@@ -505,10 +493,11 @@ WorkerUnfoldMAASparse1::operator()(std::mutex &mut)
     }
 }
 
-WorkerUnfoldMAASparse1::WorkerUnfoldMAASparse1(const UnfoldedStackContainer &container,
-                                               const FSSparseTensor &ten,
-                                               UGSTensor &outten, IntSequence c)
-  : cont(container), t(ten), out(outten), coor(std::move(c))
+WorkerUnfoldMAASparse1::WorkerUnfoldMAASparse1(const UnfoldedStackContainer& container,
+                                               const FSSparseTensor& ten, UGSTensor& outten,
+                                               IntSequence c) :
+    cont(container),
+    t(ten), out(outten), coor(std::move(c))
 {
 }
 
@@ -534,8 +523,7 @@ WorkerUnfoldMAASparse1::WorkerUnfoldMAASparse1(const UnfoldedStackContainer &con
    permutation of UPSTensor. */
 
 void
-UnfoldedStackContainer::multAndAddSparse2(const FSSparseTensor &t,
-                                          UGSTensor &out) const
+UnfoldedStackContainer::multAndAddSparse2(const FSSparseTensor& t, UGSTensor& out) const
 {
   sthread::detach_thread_group gr;
   FFSTensor dummy_f(0, numStacks(), t.dimen());
@@ -553,27 +541,27 @@ UnfoldedStackContainer::multAndAddSparse2(const FSSparseTensor &t,
    WorkerFoldMAASparse2::operator()(). */
 
 void
-WorkerUnfoldMAASparse2::operator()(std::mutex &mut)
+WorkerUnfoldMAASparse2::operator()(std::mutex& mut)
 {
-  GSSparseTensor slice(t, cont.getStackSizes(), coor,
-                       TensorDimens(cont.getStackSizes(), coor));
+  GSSparseTensor slice(t, cont.getStackSizes(), coor, TensorDimens(cont.getStackSizes(), coor));
   if (slice.getNumNonZero())
     {
       FGSTensor fslice(slice);
       UGSTensor dense_slice(fslice);
       int r1 = slice.getFirstNonZeroRow();
       int r2 = slice.getLastNonZeroRow();
-      UGSTensor dense_slice1(r1, r2-r1+1, dense_slice);
-      UGSTensor out1(r1, r2-r1+1, out);
+      UGSTensor dense_slice1(r1, r2 - r1 + 1, dense_slice);
+      UGSTensor out1(r1, r2 - r1 + 1, out);
 
       cont.multAndAddStacks(coor, dense_slice1, out1, mut);
     }
 }
 
-WorkerUnfoldMAASparse2::WorkerUnfoldMAASparse2(const UnfoldedStackContainer &container,
-                                               const FSSparseTensor &ten,
-                                               UGSTensor &outten, IntSequence c)
-  : cont(container), t(ten), out(outten), coor(std::move(c))
+WorkerUnfoldMAASparse2::WorkerUnfoldMAASparse2(const UnfoldedStackContainer& container,
+                                               const FSSparseTensor& ten, UGSTensor& outten,
+                                               IntSequence c) :
+    cont(container),
+    t(ten), out(outten), coor(std::move(c))
 {
 }
 
@@ -594,11 +582,10 @@ WorkerUnfoldMAASparse2::WorkerUnfoldMAASparse2(const UnfoldedStackContainer &con
    ‘g’ is fully symmetric, we can do the optimization harmlessly. */
 
 void
-UnfoldedStackContainer::multAndAddStacks(const IntSequence &fi,
-                                         const UGSTensor &g,
-                                         UGSTensor &out, std::mutex &mut) const
+UnfoldedStackContainer::multAndAddStacks(const IntSequence& fi, const UGSTensor& g, UGSTensor& out,
+                                         std::mutex& mut) const
 {
-  const EquivalenceSet &eset = TLStatic::getEquiv(out.dimen());
+  const EquivalenceSet& eset = TLStatic::getEquiv(out.dimen());
 
   UFSTensor dummy_u(0, numStacks(), g.dimen());
   for (Tensor::index ui = dummy_u.begin(); ui != dummy_u.end(); ++ui)
@@ -609,7 +596,7 @@ UnfoldedStackContainer::multAndAddStacks(const IntSequence &fi,
         {
           Permutation sort_per(ui.getCoor());
           sort_per.inverse();
-          for (const auto &it : eset)
+          for (const auto& it : eset)
             if (it.numClasses() == g.dimen())
               {
                 StackProduct<UGSTensor> sp(*this, it, sort_per, out.getSym());
@@ -620,7 +607,7 @@ UnfoldedStackContainer::multAndAddStacks(const IntSequence &fi,
                       kp.optimizeOrder();
                     UPSTensor ups(out.getDims(), it, sort_per, g, kp);
                     {
-                      std::unique_lock<std::mutex> lk{mut};
+                      std::unique_lock<std::mutex> lk {mut};
                       ups.addTo(out);
                     }
                   }
diff --git a/mex/sources/libkorder/tl/stack_container.hh b/mex/sources/libkorder/tl/stack_container.hh
index e5903a5509b6ae54fe1a8112dbeb9057b76f7865..53e5994b77d9aca8499eb4bf3ad4e1467a1feb2c 100644
--- a/mex/sources/libkorder/tl/stack_container.hh
+++ b/mex/sources/libkorder/tl/stack_container.hh
@@ -78,13 +78,13 @@
 #ifndef STACK_CONTAINER_H
 #define STACK_CONTAINER_H
 
-#include "int_sequence.hh"
 #include "equivalence.hh"
-#include "tl_static.hh"
-#include "t_container.hh"
+#include "int_sequence.hh"
 #include "kron_prod.hh"
 #include "permutation.hh"
 #include "sthread.hh"
+#include "t_container.hh"
+#include "tl_static.hh"
 
 /* Here is the general interface to stack container. The subclasses
    maintain IntSequence of stack sizes, i.e. size of G, g, y, and
@@ -112,30 +112,35 @@ class StackContainerInterface
 {
 public:
   using _Ctype = TensorContainer<_Ttype>;
-  enum class itype { matrix, unit, zero };
+  enum class itype
+  {
+    matrix,
+    unit,
+    zero
+  };
+
 public:
   StackContainerInterface() = default;
   virtual ~StackContainerInterface() = default;
-  virtual const IntSequence &getStackSizes() const = 0;
-  virtual IntSequence &getStackSizes() = 0;
-  virtual const IntSequence &getStackOffsets() const = 0;
-  virtual IntSequence &getStackOffsets() = 0;
+  virtual const IntSequence& getStackSizes() const = 0;
+  virtual IntSequence& getStackSizes() = 0;
+  virtual const IntSequence& getStackOffsets() const = 0;
+  virtual IntSequence& getStackOffsets() = 0;
   virtual int numConts() const = 0;
-  virtual const _Ctype &getCont(int i) const = 0;
-  virtual itype getType(int i, const Symmetry &s) const = 0;
+  virtual const _Ctype& getCont(int i) const = 0;
+  virtual itype getType(int i, const Symmetry& s) const = 0;
   virtual int numStacks() const = 0;
-  virtual bool isZero(int i, const Symmetry &s) const = 0;
-  virtual const _Ttype &getMatrix(int i, const Symmetry &s) const = 0;
-  virtual int getLengthOfMatrixStacks(const Symmetry &s) const = 0;
-  virtual int getUnitPos(const Symmetry &s) const = 0;
-  virtual std::unique_ptr<Vector> createPackedColumn(const Symmetry &s,
-                                                     const IntSequence &coor,
-                                                     int &iu) const = 0;
+  virtual bool isZero(int i, const Symmetry& s) const = 0;
+  virtual const _Ttype& getMatrix(int i, const Symmetry& s) const = 0;
+  virtual int getLengthOfMatrixStacks(const Symmetry& s) const = 0;
+  virtual int getUnitPos(const Symmetry& s) const = 0;
+  virtual std::unique_ptr<Vector> createPackedColumn(const Symmetry& s, const IntSequence& coor,
+                                                     int& iu) const
+      = 0;
   int
   getAllSize() const
   {
-    return getStackOffsets()[numStacks()-1]
-      + getStackSizes()[numStacks()-1];
+    return getStackOffsets()[numStacks() - 1] + getStackSizes()[numStacks() - 1];
   }
 };
 
@@ -152,33 +157,33 @@ public:
   using _Stype = StackContainerInterface<_Ttype>;
   using _Ctype = typename StackContainerInterface<_Ttype>::_Ctype;
   using itype = typename StackContainerInterface<_Ttype>::itype;
+
 protected:
   int num_conts;
   IntSequence stack_sizes;
   IntSequence stack_offsets;
-  std::vector<const _Ctype *> conts;
+  std::vector<const _Ctype*> conts;
+
 public:
-  StackContainer(int ns, int nc)
-    : stack_sizes(ns, 0), stack_offsets(ns, 0),
-      conts(nc)
+  StackContainer(int ns, int nc) : stack_sizes(ns, 0), stack_offsets(ns, 0), conts(nc)
   {
   }
-  const IntSequence &
+  const IntSequence&
   getStackSizes() const override
   {
     return stack_sizes;
   }
-  IntSequence &
+  IntSequence&
   getStackSizes() override
   {
     return stack_sizes;
   }
-  const IntSequence &
+  const IntSequence&
   getStackOffsets() const override
   {
     return stack_offsets;
   }
-  IntSequence &
+  IntSequence&
   getStackOffsets() override
   {
     return stack_offsets;
@@ -188,28 +193,27 @@ public:
   {
     return conts.size();
   }
-  const _Ctype &
+  const _Ctype&
   getCont(int i) const override
   {
     return *(conts[i]);
   }
-  itype getType(int i, const Symmetry &s) const override = 0;
+  itype getType(int i, const Symmetry& s) const override = 0;
   int
   numStacks() const override
   {
     return stack_sizes.size();
   }
   bool
-  isZero(int i, const Symmetry &s) const override
+  isZero(int i, const Symmetry& s) const override
   {
-    TL_RAISE_IF(i < 0 || i >= numStacks(),
-                "Wrong index to stack in StackContainer::isZero.");
+    TL_RAISE_IF(i < 0 || i >= numStacks(), "Wrong index to stack in StackContainer::isZero.");
     return (getType(i, s) == itype::zero
             || (getType(i, s) == itype::matrix && !conts[i]->check(s)));
   }
 
-  const _Ttype &
-  getMatrix(int i, const Symmetry &s) const override
+  const _Ttype&
+  getMatrix(int i, const Symmetry& s) const override
   {
     TL_RAISE_IF(isZero(i, s) || getType(i, s) == itype::unit,
                 "Matrix is not returned in StackContainer::getMatrix");
@@ -217,7 +221,7 @@ public:
   }
 
   int
-  getLengthOfMatrixStacks(const Symmetry &s) const override
+  getLengthOfMatrixStacks(const Symmetry& s) const override
   {
     int res = 0;
     int i = 0;
@@ -227,19 +231,18 @@ public:
   }
 
   int
-  getUnitPos(const Symmetry &s) const override
+  getUnitPos(const Symmetry& s) const override
   {
     if (s.dimen() != 1)
       return -1;
-    int i = numStacks()-1;
+    int i = numStacks() - 1;
     while (i >= 0 && getType(i, s) != itype::unit)
       i--;
     return i;
   }
 
   std::unique_ptr<Vector>
-  createPackedColumn(const Symmetry &s,
-                     const IntSequence &coor, int &iu) const override
+  createPackedColumn(const Symmetry& s, const IntSequence& coor, int& iu) const override
   {
     TL_RAISE_IF(s.dimen() != coor.size(),
                 "Incompatible coordinates for symmetry in StackContainer::createPackedColumn");
@@ -257,14 +260,14 @@ public:
     i = 0;
     while (i < numStacks() && getType(i, s) == itype::matrix)
       {
-        const _Ttype &t = getMatrix(i, s);
+        const _Ttype& t = getMatrix(i, s);
         Tensor::index ind(t, coor);
         Vector subres(*res, stack_offsets[i], stack_sizes[i]);
         subres = ConstGeneralMatrix(t).getCol(*ind);
         i++;
       }
     if (iu != -1)
-      (*res)[len-1] = 1;
+      (*res)[len - 1] = 1;
 
     return res;
   }
@@ -275,7 +278,7 @@ protected:
   {
     stack_offsets[0] = 0;
     for (int i = 1; i < stack_offsets.size(); i++)
-      stack_offsets[i] = stack_offsets[i-1] + stack_sizes[i-1];
+      stack_offsets[i] = stack_offsets[i - 1] + stack_sizes[i - 1];
   }
 };
 
@@ -289,26 +292,27 @@ class FoldedStackContainer : virtual public StackContainerInterface<FGSTensor>
   friend class WorkerFoldMAASparse1;
   friend class WorkerFoldMAASparse2;
   friend class WorkerFoldMAASparse4;
+
 public:
   static constexpr double fill_threshold = 0.00005;
   void
-  multAndAdd(int dim, const TensorContainer<FSSparseTensor> &c,
-             FGSTensor &out) const
+  multAndAdd(int dim, const TensorContainer<FSSparseTensor>& c, FGSTensor& out) const
   {
-    if (c.check(Symmetry{dim}))
-      multAndAdd(c.get(Symmetry{dim}), out);
+    if (c.check(Symmetry {dim}))
+      multAndAdd(c.get(Symmetry {dim}), out);
   }
-  void multAndAdd(const FSSparseTensor &t, FGSTensor &out) const;
-  void multAndAdd(int dim, const FGSContainer &c, FGSTensor &out) const;
+  void multAndAdd(const FSSparseTensor& t, FGSTensor& out) const;
+  void multAndAdd(int dim, const FGSContainer& c, FGSTensor& out) const;
+
 protected:
-  void multAndAddSparse1(const FSSparseTensor &t, FGSTensor &out) const;
-  void multAndAddSparse2(const FSSparseTensor &t, FGSTensor &out) const;
-  void multAndAddSparse3(const FSSparseTensor &t, FGSTensor &out) const;
-  void multAndAddSparse4(const FSSparseTensor &t, FGSTensor &out) const;
-  void multAndAddStacks(const IntSequence &fi, const FGSTensor &g,
-                        FGSTensor &out, std::mutex &mut) const;
-  void multAndAddStacks(const IntSequence &fi, const GSSparseTensor &g,
-                        FGSTensor &out, std::mutex &mut) const;
+  void multAndAddSparse1(const FSSparseTensor& t, FGSTensor& out) const;
+  void multAndAddSparse2(const FSSparseTensor& t, FGSTensor& out) const;
+  void multAndAddSparse3(const FSSparseTensor& t, FGSTensor& out) const;
+  void multAndAddSparse4(const FSSparseTensor& t, FGSTensor& out) const;
+  void multAndAddStacks(const IntSequence& fi, const FGSTensor& g, FGSTensor& out,
+                        std::mutex& mut) const;
+  void multAndAddStacks(const IntSequence& fi, const GSSparseTensor& g, FGSTensor& out,
+                        std::mutex& mut) const;
 };
 
 class WorkerUnfoldMAADense;
@@ -319,28 +323,31 @@ class UnfoldedStackContainer : virtual public StackContainerInterface<UGSTensor>
   friend class WorkerUnfoldMAADense;
   friend class WorkerUnfoldMAASparse1;
   friend class WorkerUnfoldMAASparse2;
+
 public:
   static constexpr double fill_threshold = 0.00005;
   void
-  multAndAdd(int dim, const TensorContainer<FSSparseTensor> &c,
-             UGSTensor &out) const
+  multAndAdd(int dim, const TensorContainer<FSSparseTensor>& c, UGSTensor& out) const
   {
-    if (c.check(Symmetry{dim}))
-      multAndAdd(c.get(Symmetry{dim}), out);
+    if (c.check(Symmetry {dim}))
+      multAndAdd(c.get(Symmetry {dim}), out);
   }
-  void multAndAdd(const FSSparseTensor &t, UGSTensor &out) const;
-  void multAndAdd(int dim, const UGSContainer &c, UGSTensor &out) const;
+  void multAndAdd(const FSSparseTensor& t, UGSTensor& out) const;
+  void multAndAdd(int dim, const UGSContainer& c, UGSTensor& out) const;
+
 protected:
-  void multAndAddSparse1(const FSSparseTensor &t, UGSTensor &out) const;
-  void multAndAddSparse2(const FSSparseTensor &t, UGSTensor &out) const;
-  void multAndAddStacks(const IntSequence &fi, const UGSTensor &g,
-                        UGSTensor &out, std::mutex &mut) const;
+  void multAndAddSparse1(const FSSparseTensor& t, UGSTensor& out) const;
+  void multAndAddSparse2(const FSSparseTensor& t, UGSTensor& out) const;
+  void multAndAddStacks(const IntSequence& fi, const UGSTensor& g, UGSTensor& out,
+                        std::mutex& mut) const;
 };
 
 /* Here is the specialization of the StackContainer. We implement
-   here the x needed in DSGE context for welfare assessment. We implement getType() and define a constructor feeding the data and sizes.
+   here the x needed in DSGE context for welfare assessment. We implement getType() and define a
+   constructor feeding the data and sizes.
 
-   It depends on four variables U(y,u,u',σ), the variable u' being introduced to enable additions with 4-variable tensors*/
+   It depends on four variables U(y,u,u',σ), the variable u' being introduced to enable additions
+   with 4-variable tensors*/
 
 template<class _Ttype>
 class XContainer : public StackContainer<_Ttype>
@@ -350,10 +357,9 @@ public:
   using _Stype = StackContainerInterface<_Ttype>;
   using _Ctype = typename _Tparent::_Ctype;
   using itype = typename _Tparent::itype;
-  XContainer(const _Ctype *g, int ng)
-    : _Tparent(1, 1)
+  XContainer(const _Ctype* g, int ng) : _Tparent(1, 1)
   {
-    _Tparent::stack_sizes = { ng };
+    _Tparent::stack_sizes = {ng};
     _Tparent::conts[0] = g;
     _Tparent::calculateOffsets();
   }
@@ -362,9 +368,9 @@ public:
      file, how z looks, and code is clear. */
 
   itype
-  getType(int i, const Symmetry &s) const override
+  getType(int i, const Symmetry& s) const override
   {
-    if (i==0)
+    if (i == 0)
       {
         if (s[2] > 0)
           return itype::zero;
@@ -374,27 +380,22 @@ public:
 
     TL_RAISE("Wrong stack index in XContainer::getType");
   }
-
 };
 
-class FoldedXContainer : public XContainer<FGSTensor>,
-                         public FoldedStackContainer
+class FoldedXContainer : public XContainer<FGSTensor>, public FoldedStackContainer
 {
 public:
   using _Ctype = TensorContainer<FGSTensor>;
-  FoldedXContainer(const _Ctype *g, int ng)
-    : XContainer<FGSTensor>(g, ng)
+  FoldedXContainer(const _Ctype* g, int ng) : XContainer<FGSTensor>(g, ng)
   {
   }
 };
 
-class UnfoldedXContainer : public XContainer<UGSTensor>,
-                           public UnfoldedStackContainer
+class UnfoldedXContainer : public XContainer<UGSTensor>, public UnfoldedStackContainer
 {
 public:
   using _Ctype = TensorContainer<UGSTensor>;
-  UnfoldedXContainer(const _Ctype *g, int ng)
-    : XContainer<UGSTensor>(g, ng)
+  UnfoldedXContainer(const _Ctype* g, int ng) : XContainer<UGSTensor>(g, ng)
   {
   }
 };
@@ -416,11 +417,9 @@ public:
   using _Stype = StackContainerInterface<_Ttype>;
   using _Ctype = typename _Tparent::_Ctype;
   using itype = typename _Tparent::itype;
-  ZContainer(const _Ctype *gss, int ngss, const _Ctype *g, int ng,
-             int ny, int nu)
-    : _Tparent(4, 2)
+  ZContainer(const _Ctype* gss, int ngss, const _Ctype* g, int ng, int ny, int nu) : _Tparent(4, 2)
   {
-    _Tparent::stack_sizes = { ngss, ng, ny, nu };
+    _Tparent::stack_sizes = {ngss, ng, ny, nu};
     _Tparent::conts[0] = gss;
     _Tparent::conts[1] = g;
     _Tparent::calculateOffsets();
@@ -430,7 +429,7 @@ public:
      file, how z looks, and code is clear. */
 
   itype
-  getType(int i, const Symmetry &s) const override
+  getType(int i, const Symmetry& s) const override
   {
     if (i == 0)
       return itype::matrix;
@@ -443,14 +442,14 @@ public:
       }
     if (i == 2)
       {
-        if (s == Symmetry{1, 0, 0, 0})
+        if (s == Symmetry {1, 0, 0, 0})
           return itype::unit;
         else
           return itype::zero;
       }
     if (i == 3)
       {
-        if (s == Symmetry{0, 1, 0, 0})
+        if (s == Symmetry {0, 1, 0, 0})
           return itype::unit;
         else
           return itype::zero;
@@ -458,29 +457,24 @@ public:
 
     TL_RAISE("Wrong stack index in ZContainer::getType");
   }
-
 };
 
-class FoldedZContainer : public ZContainer<FGSTensor>,
-                         public FoldedStackContainer
+class FoldedZContainer : public ZContainer<FGSTensor>, public FoldedStackContainer
 {
 public:
   using _Ctype = TensorContainer<FGSTensor>;
-  FoldedZContainer(const _Ctype *gss, int ngss, const _Ctype *g, int ng,
-                   int ny, int nu)
-    : ZContainer<FGSTensor>(gss, ngss, g, ng, ny, nu)
+  FoldedZContainer(const _Ctype* gss, int ngss, const _Ctype* g, int ng, int ny, int nu) :
+      ZContainer<FGSTensor>(gss, ngss, g, ng, ny, nu)
   {
   }
 };
 
-class UnfoldedZContainer : public ZContainer<UGSTensor>,
-                           public UnfoldedStackContainer
+class UnfoldedZContainer : public ZContainer<UGSTensor>, public UnfoldedStackContainer
 {
 public:
   using _Ctype = TensorContainer<UGSTensor>;
-  UnfoldedZContainer(const _Ctype *gss, int ngss, const _Ctype *g, int ng,
-                     int ny, int nu)
-    : ZContainer<UGSTensor>(gss, ngss, g, ng, ny, nu)
+  UnfoldedZContainer(const _Ctype* gss, int ngss, const _Ctype* g, int ng, int ny, int nu) :
+      ZContainer<UGSTensor>(gss, ngss, g, ng, ny, nu)
   {
   }
 };
@@ -504,10 +498,9 @@ public:
   using _Stype = StackContainerInterface<_Ttype>;
   using _Ctype = typename StackContainer<_Ttype>::_Ctype;
   using itype = typename StackContainer<_Ttype>::itype;
-  GContainer(const _Ctype *gs, int ngs, int nu)
-    : StackContainer<_Ttype>(4, 1)
+  GContainer(const _Ctype* gs, int ngs, int nu) : StackContainer<_Ttype>(4, 1)
   {
-    _Tparent::stack_sizes = { ngs, nu, nu, 1 };
+    _Tparent::stack_sizes = {ngs, nu, nu, 1};
     _Tparent::conts[0] = gs;
     _Tparent::calculateOffsets();
   }
@@ -517,18 +510,18 @@ public:
      information. */
 
   itype
-  getType(int i, const Symmetry &s) const override
+  getType(int i, const Symmetry& s) const override
   {
     if (i == 0)
       {
-        if (s[2] > 0 || s == Symmetry{0, 0, 0, 1})
+        if (s[2] > 0 || s == Symmetry {0, 0, 0, 1})
           return itype::zero;
         else
           return itype::matrix;
       }
     if (i == 1)
       {
-        if (s == Symmetry{0, 0, 1, 0})
+        if (s == Symmetry {0, 0, 1, 0})
           return itype::unit;
         else
           return itype::zero;
@@ -537,7 +530,7 @@ public:
       return itype::zero;
     if (i == 3)
       {
-        if (s == Symmetry{0, 0, 0, 1})
+        if (s == Symmetry {0, 0, 0, 1})
           return itype::unit;
         else
           return itype::zero;
@@ -545,27 +538,22 @@ public:
 
     TL_RAISE("Wrong stack index in GContainer::getType");
   }
-
 };
 
-class FoldedGContainer : public GContainer<FGSTensor>,
-                         public FoldedStackContainer
+class FoldedGContainer : public GContainer<FGSTensor>, public FoldedStackContainer
 {
 public:
   using _Ctype = TensorContainer<FGSTensor>;
-  FoldedGContainer(const _Ctype *gs, int ngs, int nu)
-    : GContainer<FGSTensor>(gs, ngs, nu)
+  FoldedGContainer(const _Ctype* gs, int ngs, int nu) : GContainer<FGSTensor>(gs, ngs, nu)
   {
   }
 };
 
-class UnfoldedGContainer : public GContainer<UGSTensor>,
-                           public UnfoldedStackContainer
+class UnfoldedGContainer : public GContainer<UGSTensor>, public UnfoldedStackContainer
 {
 public:
   using _Ctype = TensorContainer<UGSTensor>;
-  UnfoldedGContainer(const _Ctype *gs, int ngs, int nu)
-    : GContainer<UGSTensor>(gs, ngs, nu)
+  UnfoldedGContainer(const _Ctype* gs, int ngs, int nu) : GContainer<UGSTensor>(gs, ngs, nu)
   {
   }
 };
@@ -583,19 +571,19 @@ public:
   using _Stype = StackContainerInterface<_Ttype>;
   using _Ctype = typename _Stype::_Ctype;
   using itype = typename _Stype::itype;
+
 protected:
-  const _Stype &stack_cont;
+  const _Stype& stack_cont;
   InducedSymmetries syms;
   Permutation per;
+
 public:
-  StackProduct(const _Stype &sc, const Equivalence &e,
-               const Symmetry &os)
-    : stack_cont(sc), syms(e, os), per(e)
+  StackProduct(const _Stype& sc, const Equivalence& e, const Symmetry& os) :
+      stack_cont(sc), syms(e, os), per(e)
   {
   }
-  StackProduct(const _Stype &sc, const Equivalence &e,
-               const Permutation &p, const Symmetry &os)
-    : stack_cont(sc), syms(e, p, os), per(e, p)
+  StackProduct(const _Stype& sc, const Equivalence& e, const Permutation& p, const Symmetry& os) :
+      stack_cont(sc), syms(e, p, os), per(e, p)
   {
   }
   int
@@ -608,16 +596,15 @@ public:
   {
     return stack_cont.getAllSize();
   }
-  const Symmetry &
+  const Symmetry&
   getProdSym(int ip) const
   {
     return syms[ip];
   }
   bool
-  isZero(const IntSequence &istacks) const
+  isZero(const IntSequence& istacks) const
   {
-    TL_RAISE_IF(istacks.size() != dimen(),
-                "Wrong istacks coordinates for StackProduct::isZero");
+    TL_RAISE_IF(istacks.size() != dimen(), "Wrong istacks coordinates for StackProduct::isZero");
 
     bool res = false;
     int i = 0;
@@ -631,19 +618,18 @@ public:
   {
     TL_RAISE_IF(is < 0 || is >= stack_cont.numStacks(),
                 "Wrong index to stack in StackProduct::getType");
-    TL_RAISE_IF(ip < 0 || ip >= dimen(),
-                "Wrong index to stack container in StackProduct::getType");
+    TL_RAISE_IF(ip < 0 || ip >= dimen(), "Wrong index to stack container in StackProduct::getType");
     return stack_cont.getType(is, syms[ip]);
   }
 
-  const _Ttype &
+  const _Ttype&
   getMatrix(int is, int ip) const
   {
     return stack_cont.getMatrix(is, syms[ip]);
   }
 
   std::vector<std::unique_ptr<Vector>>
-  createPackedColumns(const IntSequence &coor, IntSequence &iu) const
+  createPackedColumns(const IntSequence& coor, IntSequence& iu) const
   {
     TL_RAISE_IF(iu.size() != dimen(),
                 "Wrong storage length for unit flags in StackProduct::createPackedColumns");
@@ -669,7 +655,7 @@ public:
   }
 
   int
-  numMatrices(const IntSequence &istacks) const
+  numMatrices(const IntSequence& istacks) const
   {
     TL_RAISE_IF(istacks.size() != dimen(),
                 "Wrong size of stack coordinates in StackContainer::numMatrices");
@@ -702,8 +688,7 @@ public:
      the KronProdStack behaves like KronProdAll (i.e. no optimization
      is done). */
 
-  KronProdStack(const _Ptype &sp, const IntSequence &istack)
-    : KronProdAllOptim(sp.dimen())
+  KronProdStack(const _Ptype& sp, const IntSequence& istack) : KronProdAllOptim(sp.dimen())
   {
     TL_RAISE_IF(sp.dimen() != istack.size(),
                 "Wrong stack product dimension for KronProdStack constructor");
@@ -716,7 +701,7 @@ public:
           setUnit(i, sp.getSize(istack[i]));
         if (sp.getType(istack[i], i) == _Stype::itype::matrix)
           {
-            const TwoDMatrix &m = sp.getMatrix(istack[i], i);
+            const TwoDMatrix& m = sp.getMatrix(istack[i], i);
             TL_RAISE_IF(m.nrows() != sp.getSize(istack[i]),
                         "Wrong size of returned matrix in KronProdStack constructor");
             setMat(i, m);
@@ -727,95 +712,93 @@ public:
 
 class WorkerFoldMAADense : public sthread::detach_thread
 {
-  const FoldedStackContainer &cont;
+  const FoldedStackContainer& cont;
   Symmetry sym;
-  const FGSContainer &dense_cont;
-  FGSTensor &out;
+  const FGSContainer& dense_cont;
+  FGSTensor& out;
+
 public:
-  WorkerFoldMAADense(const FoldedStackContainer &container,
-                     Symmetry s,
-                     const FGSContainer &dcontainer,
-                     FGSTensor &outten);
-  void operator()(std::mutex &mut) override;
+  WorkerFoldMAADense(const FoldedStackContainer& container, Symmetry s,
+                     const FGSContainer& dcontainer, FGSTensor& outten);
+  void operator()(std::mutex& mut) override;
 };
 
 class WorkerFoldMAASparse1 : public sthread::detach_thread
 {
-  const FoldedStackContainer &cont;
-  const FSSparseTensor &t;
-  FGSTensor &out;
+  const FoldedStackContainer& cont;
+  const FSSparseTensor& t;
+  FGSTensor& out;
   IntSequence coor;
+
 public:
-  WorkerFoldMAASparse1(const FoldedStackContainer &container,
-                       const FSSparseTensor &ten,
-                       FGSTensor &outten, IntSequence c);
-  void operator()(std::mutex &mut) override;
+  WorkerFoldMAASparse1(const FoldedStackContainer& container, const FSSparseTensor& ten,
+                       FGSTensor& outten, IntSequence c);
+  void operator()(std::mutex& mut) override;
 };
 
 class WorkerFoldMAASparse2 : public sthread::detach_thread
 {
-  const FoldedStackContainer &cont;
-  const FSSparseTensor &t;
-  FGSTensor &out;
+  const FoldedStackContainer& cont;
+  const FSSparseTensor& t;
+  FGSTensor& out;
   IntSequence coor;
+
 public:
-  WorkerFoldMAASparse2(const FoldedStackContainer &container,
-                       const FSSparseTensor &ten,
-                       FGSTensor &outten, IntSequence c);
-  void operator()(std::mutex &mut) override;
+  WorkerFoldMAASparse2(const FoldedStackContainer& container, const FSSparseTensor& ten,
+                       FGSTensor& outten, IntSequence c);
+  void operator()(std::mutex& mut) override;
 };
 
 class WorkerFoldMAASparse4 : public sthread::detach_thread
 {
-  const FoldedStackContainer &cont;
-  const FSSparseTensor &t;
-  FGSTensor &out;
+  const FoldedStackContainer& cont;
+  const FSSparseTensor& t;
+  FGSTensor& out;
   IntSequence coor;
+
 public:
-  WorkerFoldMAASparse4(const FoldedStackContainer &container,
-                       const FSSparseTensor &ten,
-                       FGSTensor &outten, IntSequence c);
-  void operator()(std::mutex &mut) override;
+  WorkerFoldMAASparse4(const FoldedStackContainer& container, const FSSparseTensor& ten,
+                       FGSTensor& outten, IntSequence c);
+  void operator()(std::mutex& mut) override;
 };
 
 class WorkerUnfoldMAADense : public sthread::detach_thread
 {
-  const UnfoldedStackContainer &cont;
+  const UnfoldedStackContainer& cont;
   Symmetry sym;
-  const UGSContainer &dense_cont;
-  UGSTensor &out;
+  const UGSContainer& dense_cont;
+  UGSTensor& out;
+
 public:
-  WorkerUnfoldMAADense(const UnfoldedStackContainer &container,
-                       Symmetry s,
-                       const UGSContainer &dcontainer,
-                       UGSTensor &outten);
-  void operator()(std::mutex &mut) override;
+  WorkerUnfoldMAADense(const UnfoldedStackContainer& container, Symmetry s,
+                       const UGSContainer& dcontainer, UGSTensor& outten);
+  void operator()(std::mutex& mut) override;
 };
 
 class WorkerUnfoldMAASparse1 : public sthread::detach_thread
 {
-  const UnfoldedStackContainer &cont;
-  const FSSparseTensor &t;
-  UGSTensor &out;
+  const UnfoldedStackContainer& cont;
+  const FSSparseTensor& t;
+  UGSTensor& out;
   IntSequence coor;
+
 public:
-  WorkerUnfoldMAASparse1(const UnfoldedStackContainer &container,
-                         const FSSparseTensor &ten,
-                         UGSTensor &outten, IntSequence c);
-  void operator()(std::mutex &mut) override;
+  WorkerUnfoldMAASparse1(const UnfoldedStackContainer& container, const FSSparseTensor& ten,
+                         UGSTensor& outten, IntSequence c);
+  void operator()(std::mutex& mut) override;
 };
 
 class WorkerUnfoldMAASparse2 : public sthread::detach_thread
 {
-  const UnfoldedStackContainer &cont;
-  const FSSparseTensor &t;
-  UGSTensor &out;
+  const UnfoldedStackContainer& cont;
+  const FSSparseTensor& t;
+  UGSTensor& out;
   IntSequence coor;
+
 public:
-  WorkerUnfoldMAASparse2(const UnfoldedStackContainer &container,
-                         const FSSparseTensor &ten,
-                         UGSTensor &outten, IntSequence c);
-  void operator()(std::mutex &mut) override;
+  WorkerUnfoldMAASparse2(const UnfoldedStackContainer& container, const FSSparseTensor& ten,
+                         UGSTensor& outten, IntSequence c);
+  void operator()(std::mutex& mut) override;
 };
 
 #endif
diff --git a/mex/sources/libkorder/tl/symmetry.cc b/mex/sources/libkorder/tl/symmetry.cc
index 46bc527bd696a6d15d632ef65f7022f48f34348a..8c385ab46bc76b6a7c72f0b5a4c0f6c25b0f7f28 100644
--- a/mex/sources/libkorder/tl/symmetry.cc
+++ b/mex/sources/libkorder/tl/symmetry.cc
@@ -31,11 +31,10 @@
    Thus the constructed sequence must be (1,1), meaning that we picked one
    y and one u. */
 
-Symmetry::Symmetry(const Symmetry &sy, const OrdSequence &cl)
-  : IntSequence(sy.num())
+Symmetry::Symmetry(const Symmetry& sy, const OrdSequence& cl) : IntSequence(sy.num())
 {
-  const std::vector<int> &se = cl.getData();
-  TL_RAISE_IF(sy.dimen() <= se[se.size()-1],
+  const std::vector<int>& se = cl.getData();
+  TL_RAISE_IF(sy.dimen() <= se[se.size() - 1],
               "Sequence is not reachable by symmetry in IntSequence()");
   for (int i = 0; i < size(); i++)
     operator[](i) = 0;
@@ -58,7 +57,7 @@ Symmetry::findClass(int i) const
     }
   while (j < size() && sum <= i);
 
-  return j-1;
+  return j - 1;
 }
 
 /* The symmetry is full if it allows for any permutation of indices. It
@@ -77,8 +76,7 @@ Symmetry::isFull() const
 /* Construct a symiterator of given dimension, starting from the given
    symmetry. */
 
-symiterator::symiterator(int dim_arg, Symmetry run_arg)
-  : dim{dim_arg}, run(std::move(run_arg))
+symiterator::symiterator(int dim_arg, Symmetry run_arg) : dim {dim_arg}, run(std::move(run_arg))
 {
 }
 
@@ -88,7 +86,7 @@ symiterator::symiterator(int dim_arg, Symmetry run_arg)
    end, we recreate the subordinal symmetry set and set the subordinal
    iterator to the beginning. */
 
-symiterator &
+symiterator&
 symiterator::operator++()
 {
   if (run[0] == dim)
@@ -100,29 +98,28 @@ symiterator::operator++()
     }
   else
     {
-      symiterator subit{dim-run[0], Symmetry(run, run.size()-1)};
+      symiterator subit {dim - run[0], Symmetry(run, run.size() - 1)};
       ++subit;
-      if (run[1] == dim-run[0]+1)
+      if (run[1] == dim - run[0] + 1)
         {
           run[0]++;
           run[1] = 0;
           /* subit is equal to the past-the-end iterator, so the range
              2…(size()−1) is already set to 0 */
-          run[run.size()-1] = dim-run[0];
+          run[run.size() - 1] = dim - run[0];
         }
     }
   return *this;
 }
 
-InducedSymmetries::InducedSymmetries(const Equivalence &e, const Symmetry &s)
+InducedSymmetries::InducedSymmetries(const Equivalence& e, const Symmetry& s)
 {
-  for (const auto &i : e)
+  for (const auto& i : e)
     emplace_back(s, i);
 }
 
 // InducedSymmetries permuted constructor code
-InducedSymmetries::InducedSymmetries(const Equivalence &e, const Permutation &p,
-                                     const Symmetry &s)
+InducedSymmetries::InducedSymmetries(const Equivalence& e, const Permutation& p, const Symmetry& s)
 {
   for (int i = 0; i < e.numClasses(); i++)
     {
diff --git a/mex/sources/libkorder/tl/symmetry.hh b/mex/sources/libkorder/tl/symmetry.hh
index 671c5410076195f4b4b410c68872708469c45f99..180b34b1574a52122d30176211baf4d710e93b86 100644
--- a/mex/sources/libkorder/tl/symmetry.hh
+++ b/mex/sources/libkorder/tl/symmetry.hh
@@ -54,11 +54,11 @@
 #include "equivalence.hh"
 #include "int_sequence.hh"
 
-#include <list>
-#include <vector>
 #include <initializer_list>
-#include <utility>
+#include <list>
 #include <memory>
+#include <utility>
+#include <vector>
 
 /* Clear. The method isFull() returns true if and only if the symmetry
    allows for any permutation of indices.
@@ -71,22 +71,19 @@ class Symmetry : public IntSequence
 {
 public:
   // Constructor allocating a given length of (zero-initialized) data
-  explicit Symmetry(int len)
-    : IntSequence(len, 0)
+  explicit Symmetry(int len) : IntSequence(len, 0)
   {
   }
   /* Constructor using an initializer list, that gives the contents of the
      Symmetry. Typically used for symmetries of the form yⁿ, yⁿuᵐ, yⁿuᵐσᵏ */
-  Symmetry(std::initializer_list<int> init)
-    : IntSequence(std::move(init))
+  Symmetry(std::initializer_list<int> init) : IntSequence(std::move(init))
   {
   }
   // Constructor of implied symmetry for a symmetry and an equivalence class
-  Symmetry(const Symmetry &s, const OrdSequence &cl);
+  Symmetry(const Symmetry& s, const OrdSequence& cl);
   /* Subsymmetry, which takes the given length of symmetry from the end (shares
      data pointer) */
-  Symmetry(Symmetry &s, int len)
-    : IntSequence(s, s.size()-len, s.size())
+  Symmetry(Symmetry& s, int len) : IntSequence(s, s.size() - len, s.size())
   {
   }
 
@@ -119,22 +116,23 @@ class symiterator
 {
   const int dim;
   Symmetry run;
+
 public:
   symiterator(int dim_arg, Symmetry run_arg);
   ~symiterator() = default;
-  symiterator &operator++();
-  const Symmetry &
+  symiterator& operator++();
+  const Symmetry&
   operator*() const
   {
     return run;
   }
   bool
-  operator=(const symiterator &it)
+  operator=(const symiterator& it)
   {
     return dim == it.dim && run == it.run;
   }
   bool
-  operator!=(const symiterator &it)
+  operator!=(const symiterator& it)
   {
     return !operator=(it);
   }
@@ -158,23 +156,22 @@ class SymmetrySet
 public:
   const int len;
   const int dim;
-  SymmetrySet(int dim_arg, int len_arg)
-    : len(len_arg), dim(dim_arg)
+  SymmetrySet(int dim_arg, int len_arg) : len(len_arg), dim(dim_arg)
   {
   }
   symiterator
   begin() const
   {
     Symmetry run(len);
-    run[len-1] = dim;
-    return { dim, run };
+    run[len - 1] = dim;
+    return {dim, run};
   }
   symiterator
   end() const
   {
     Symmetry run(len);
-    run[0] = dim+1;
-    return { dim, run };
+    run[0] = dim + 1;
+    return {dim, run};
   }
 };
 
@@ -185,8 +182,8 @@ public:
 class InducedSymmetries : public std::vector<Symmetry>
 {
 public:
-  InducedSymmetries(const Equivalence &e, const Symmetry &s);
-  InducedSymmetries(const Equivalence &e, const Permutation &p, const Symmetry &s);
+  InducedSymmetries(const Equivalence& e, const Symmetry& s);
+  InducedSymmetries(const Equivalence& e, const Permutation& p, const Symmetry& s);
   void print() const;
 };
 
diff --git a/mex/sources/libkorder/tl/t_container.cc b/mex/sources/libkorder/tl/t_container.cc
index d5090bd79ebdf796c59c734fcb8d71f2a352629e..87841381de48ae4663be737aabf7994cd22835bb 100644
--- a/mex/sources/libkorder/tl/t_container.cc
+++ b/mex/sources/libkorder/tl/t_container.cc
@@ -24,10 +24,9 @@
 #include "pyramid_prod.hh"
 
 // UGSContainer conversion from FGSContainer
-UGSContainer::UGSContainer(const FGSContainer &c)
-  : TensorContainer<UGSTensor>(c.num())
+UGSContainer::UGSContainer(const FGSContainer& c) : TensorContainer<UGSTensor>(c.num())
 {
-  for (const auto &it : c)
+  for (const auto& it : c)
     insert(std::make_unique<UGSTensor>(*(it.second)));
 }
 
@@ -43,16 +42,16 @@ UGSContainer::UGSContainer(const FGSContainer &c)
    data to ‘out’. This is done by UPSTensor method addTo(). */
 
 void
-UGSContainer::multAndAdd(const UGSTensor &t, UGSTensor &out) const
+UGSContainer::multAndAdd(const UGSTensor& t, UGSTensor& out) const
 {
   int l = t.dimen();
   int k = out.dimen();
-  const EquivalenceSet &eset = TLStatic::getEquiv(k);
+  const EquivalenceSet& eset = TLStatic::getEquiv(k);
 
-  for (const auto &it : eset)
+  for (const auto& it : eset)
     if (it.numClasses() == l)
       {
-        std::vector<const UGSTensor *> ts = fetchTensors(out.getSym(), it);
+        std::vector<const UGSTensor*> ts = fetchTensors(out.getSym(), it);
         KronProdAllOptim kp(l);
         for (int i = 0; i < l; i++)
           kp.setMat(i, *(ts[i]));
@@ -63,10 +62,9 @@ UGSContainer::multAndAdd(const UGSTensor &t, UGSTensor &out) const
 }
 
 // FGSContainer conversion from UGSContainer
-FGSContainer::FGSContainer(const UGSContainer &c)
-  : TensorContainer<FGSTensor>(c.num())
+FGSContainer::FGSContainer(const UGSContainer& c) : TensorContainer<FGSTensor>(c.num())
 {
-  for (const auto &it : c)
+  for (const auto& it : c)
     insert(std::make_unique<FGSTensor>(*(it.second)));
 }
 
@@ -74,7 +72,7 @@ FGSContainer::FGSContainer(const UGSContainer &c)
 /* Here we perform one step of the Faà Di Bruno operation. We call the
    multAndAdd() for unfolded tensor. */
 void
-FGSContainer::multAndAdd(const FGSTensor &t, FGSTensor &out) const
+FGSContainer::multAndAdd(const FGSTensor& t, FGSTensor& out) const
 {
   UGSTensor ut(t);
   multAndAdd(ut, out);
@@ -84,17 +82,16 @@ FGSContainer::multAndAdd(const FGSTensor &t, FGSTensor &out) const
 /* This is the same as UGSContainer::multAndAdd() but we do not construct
    UPSTensor from the Kronecker product, but FPSTensor. */
 void
-FGSContainer::multAndAdd(const UGSTensor &t, FGSTensor &out) const
+FGSContainer::multAndAdd(const UGSTensor& t, FGSTensor& out) const
 {
   int l = t.dimen();
   int k = out.dimen();
-  const EquivalenceSet &eset = TLStatic::getEquiv(k);
+  const EquivalenceSet& eset = TLStatic::getEquiv(k);
 
-  for (const auto &it : eset)
+  for (const auto& it : eset)
     if (it.numClasses() == l)
       {
-        std::vector<const FGSTensor *> ts
-          = fetchTensors(out.getSym(), it);
+        std::vector<const FGSTensor*> ts = fetchTensors(out.getSym(), it);
         KronProdAllOptim kp(l);
         for (int i = 0; i < l; i++)
           kp.setMat(i, *(ts[i]));
@@ -108,9 +105,8 @@ FGSContainer::multAndAdd(const UGSTensor &t, FGSTensor &out) const
    ‘num’ indices from interval ‘start’ (including) to ‘end’ (excluding). If
    there are not ‘num’ of such indices, the shorter vector is returned. */
 Tensor::index
-FGSContainer::getIndices(int num, std::vector<IntSequence> &out,
-                         const Tensor::index &start,
-                         const Tensor::index &end)
+FGSContainer::getIndices(int num, std::vector<IntSequence>& out, const Tensor::index& start,
+                         const Tensor::index& end)
 {
   out.clear();
   int i = 0;
diff --git a/mex/sources/libkorder/tl/t_container.hh b/mex/sources/libkorder/tl/t_container.hh
index 8eef8938109cfe484590d25b4d4eacb65364c643..f99f630f296e269102c412cb4d626db17b69206c 100644
--- a/mex/sources/libkorder/tl/t_container.hh
+++ b/mex/sources/libkorder/tl/t_container.hh
@@ -61,18 +61,18 @@
 #ifndef T_CONTAINER_H
 #define T_CONTAINER_H
 
-#include "symmetry.hh"
+#include "Vector.hh"
+#include "equivalence.hh"
 #include "gs_tensor.hh"
+#include "rfs_tensor.hh"
+#include "sparse_tensor.hh"
+#include "symmetry.hh"
 #include "tl_exception.hh"
 #include "tl_static.hh"
-#include "sparse_tensor.hh"
-#include "equivalence.hh"
-#include "rfs_tensor.hh"
-#include "Vector.hh"
 
 #include <map>
-#include <string>
 #include <memory>
+#include <string>
 #include <utility>
 
 // ltsym predicate
@@ -81,7 +81,7 @@
 struct ltsym
 {
   bool
-  operator()(const Symmetry &s1, const Symmetry &s2) const
+  operator()(const Symmetry& s1, const Symmetry& s2) const
   {
     return s1 < s2;
   }
@@ -107,68 +107,64 @@ class TensorContainer
 {
 protected:
   using _Map = std::map<Symmetry, std::unique_ptr<_Ttype>, ltsym>;
+
 private:
   int n;
   _Map m;
+
 public:
-  TensorContainer(int nn)
-    : n(nn)
+  TensorContainer(int nn) : n(nn)
   {
   }
   /* This is just a copy constructor. This makes a hard copy of all tensors. */
-  TensorContainer(const TensorContainer<_Ttype> &c)
-    : n(c.n)
+  TensorContainer(const TensorContainer<_Ttype>& c) : n(c.n)
   {
-    for (const auto &it : c.m)
+    for (const auto& it : c.m)
       insert(std::make_unique<_Ttype>(*(it.second)));
   }
-  TensorContainer(TensorContainer<_Ttype> &&) = default;
+  TensorContainer(TensorContainer<_Ttype>&&) = default;
 
   // TensorContainer subtensor constructor
   /* This constructor constructs a new tensor container, whose tensors
      are in-place subtensors of the given container. */
-  TensorContainer(int first_row, int num, TensorContainer<_Ttype> &c)
-    : n(c.n)
+  TensorContainer(int first_row, int num, TensorContainer<_Ttype>& c) : n(c.n)
   {
-    for (const auto &it : c.m)
+    for (const auto& it : c.m)
       insert(std::make_unique<_Ttype>(first_row, num, *(it.second)));
   }
 
-  TensorContainer<_Ttype> &
-  operator=(const TensorContainer<_Ttype> &c)
+  TensorContainer<_Ttype>&
+  operator=(const TensorContainer<_Ttype>& c)
   {
     n = c.n;
     m.clear();
-    for (const auto &it : c.m)
+    for (const auto& it : c.m)
       insert(std::make_unique<_Ttype>(*(it.second)));
   }
-  TensorContainer<_Ttype> &operator=(TensorContainer<_Ttype> &&) = default;
+  TensorContainer<_Ttype>& operator=(TensorContainer<_Ttype>&&) = default;
 
-  const _Ttype &
-  get(const Symmetry &s) const
+  const _Ttype&
+  get(const Symmetry& s) const
   {
-    TL_RAISE_IF(s.num() != num(),
-                "Incompatible symmetry lookup in TensorContainer::get");
+    TL_RAISE_IF(s.num() != num(), "Incompatible symmetry lookup in TensorContainer::get");
     auto it = m.find(s);
     TL_RAISE_IF(it == m.end(), "Symmetry not found in TensorContainer::get");
     return *(it->second);
   }
 
-  _Ttype &
-  get(const Symmetry &s)
+  _Ttype&
+  get(const Symmetry& s)
   {
-    TL_RAISE_IF(s.num() != num(),
-                "Incompatible symmetry lookup in TensorContainer::get");
+    TL_RAISE_IF(s.num() != num(), "Incompatible symmetry lookup in TensorContainer::get");
     auto it = m.find(s);
     TL_RAISE_IF(it == m.end(), "Symmetry not found in TensorContainer::get");
     return *(it->second);
   }
 
   bool
-  check(const Symmetry &s) const
+  check(const Symmetry& s) const
   {
-    TL_RAISE_IF(s.num() != num(),
-                "Incompatible symmetry lookup in TensorContainer::check");
+    TL_RAISE_IF(s.num() != num(), "Incompatible symmetry lookup in TensorContainer::check");
     auto it = m.find(s);
     return it != m.end();
   }
@@ -178,15 +174,14 @@ public:
   {
     TL_RAISE_IF(t->getSym().num() != num(),
                 "Incompatible symmetry insertion in TensorContainer::insert");
-    TL_RAISE_IF(check(t->getSym()),
-                "Tensor already in container in TensorContainer::insert");
+    TL_RAISE_IF(check(t->getSym()), "Tensor already in container in TensorContainer::insert");
     if (!t->isFinite())
       throw TLException(__FILE__, __LINE__, "NaN or Inf asserted in TensorContainer::insert");
     m.emplace(t->getSym(), std::move(t));
   }
 
   void
-  remove(const Symmetry &s)
+  remove(const Symmetry& s)
   {
     m.erase(s);
   }
@@ -201,9 +196,8 @@ public:
   getMaxDim() const
   {
     int res = -1;
-    for (const auto &run : m)
-      if (int dim { run.first.dimen() };
-          dim > res)
+    for (const auto& run : m)
+      if (int dim {run.first.dimen()}; dim > res)
         res = dim;
     return res;
   }
@@ -213,7 +207,7 @@ public:
   print() const
   {
     std::cout << "Tensor container: nvars=" << n << ", tensors=" << m.size() << '\n';
-    for (auto &it : *this)
+    for (auto& it : *this)
       {
         std::cout << "Symmetry: ";
         it.first.print();
@@ -223,12 +217,12 @@ public:
 
   /* Output to the Memory Map. */
   void
-  writeMMap(std::map<std::string, ConstTwoDMatrix> &mm, const std::string &prefix) const
+  writeMMap(std::map<std::string, ConstTwoDMatrix>& mm, const std::string& prefix) const
   {
-    for (auto &it : *this)
+    for (auto& it : *this)
       {
         std::string lname = prefix + "_g";
-        const Symmetry &sym = it.first;
+        const Symmetry& sym = it.first;
         for (int i = 0; i < sym.num(); i++)
           lname += '_' + std::to_string(sym[i]);
         mm.emplace(lname, ConstTwoDMatrix(*(it.second)));
@@ -239,10 +233,10 @@ public:
      through all equivalence classes, calculate implied symmetry, and
      fetch its tensor storing it in the same order to the vector. */
 
-  std::vector<const _Ttype *>
-  fetchTensors(const Symmetry &rsym, const Equivalence &e) const
+  std::vector<const _Ttype*>
+  fetchTensors(const Symmetry& rsym, const Equivalence& e) const
   {
-    std::vector<const _Ttype *> res(e.numClasses());
+    std::vector<const _Ttype*> res(e.numClasses());
     int i = 0;
     for (auto it = e.begin(); it != e.end(); ++it, i++)
       {
@@ -288,12 +282,11 @@ class FGSContainer;
 class UGSContainer : public TensorContainer<UGSTensor>
 {
 public:
-  UGSContainer(int nn)
-    : TensorContainer<UGSTensor>(nn)
+  UGSContainer(int nn) : TensorContainer<UGSTensor>(nn)
   {
   }
-  UGSContainer(const FGSContainer &c);
-  void multAndAdd(const UGSTensor &t, UGSTensor &out) const;
+  UGSContainer(const FGSContainer& c);
+  void multAndAdd(const UGSTensor& t, UGSTensor& out) const;
 };
 
 /* Here is a container storing FGSTensor’s. We declare two versions of
@@ -311,18 +304,18 @@ public:
 class FGSContainer : public TensorContainer<FGSTensor>
 {
   static constexpr int num_one_time = 10;
+
 public:
-  FGSContainer(int nn)
-    : TensorContainer<FGSTensor>(nn)
+  FGSContainer(int nn) : TensorContainer<FGSTensor>(nn)
   {
   }
-  FGSContainer(const UGSContainer &c);
-  void multAndAdd(const FGSTensor &t, FGSTensor &out) const;
-  void multAndAdd(const UGSTensor &t, FGSTensor &out) const;
+  FGSContainer(const UGSContainer& c);
+  void multAndAdd(const FGSTensor& t, FGSTensor& out) const;
+  void multAndAdd(const UGSTensor& t, FGSTensor& out) const;
+
 private:
-  static Tensor::index getIndices(int num, std::vector<IntSequence> &out,
-                                  const Tensor::index &start,
-                                  const Tensor::index &end);
+  static Tensor::index getIndices(int num, std::vector<IntSequence>& out,
+                                  const Tensor::index& start, const Tensor::index& end);
 };
 
 #endif
diff --git a/mex/sources/libkorder/tl/t_polynomial.cc b/mex/sources/libkorder/tl/t_polynomial.cc
index 85ba58e9395a6ce3f38b684a24d57eff8d94d21b..5c2d471894cfb322a2a8012c9755527120b6670f 100644
--- a/mex/sources/libkorder/tl/t_polynomial.cc
+++ b/mex/sources/libkorder/tl/t_polynomial.cc
@@ -25,12 +25,12 @@
 /* This method constructs unfolded ‘ut’ of higher dimension, deleting
    the previous. */
 
-const URSingleTensor &
+const URSingleTensor&
 PowerProvider::getNext(dummy<URSingleTensor>)
 {
   if (ut)
     {
-      auto ut_new = std::make_unique<URSingleTensor>(nv, ut->dimen()+1);
+      auto ut_new = std::make_unique<URSingleTensor>(nv, ut->dimen() + 1);
       KronProd::kronMult(ConstVector(origv), ConstVector(ut->getData()), ut_new->getData());
       ut = std::move(ut_new);
     }
@@ -45,7 +45,7 @@ PowerProvider::getNext(dummy<URSingleTensor>)
 // PowerProvider::getNext() folded code
 /* This method just constructs next unfolded ‘ut’ and creates folded ‘ft’. */
 
-const FRSingleTensor &
+const FRSingleTensor&
 PowerProvider::getNext(dummy<FRSingleTensor>)
 {
   getNext<URSingleTensor>();
@@ -53,16 +53,16 @@ PowerProvider::getNext(dummy<FRSingleTensor>)
   return *ft;
 }
 
-UTensorPolynomial::UTensorPolynomial(const FTensorPolynomial &fp)
-  : TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>(fp.nrows(), fp.nvars())
+UTensorPolynomial::UTensorPolynomial(const FTensorPolynomial& fp) :
+    TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>(fp.nrows(), fp.nvars())
 {
-  for (const auto &it : fp)
+  for (const auto& it : fp)
     insert(std::make_unique<UFSTensor>(*(it.second)));
 }
 
-FTensorPolynomial::FTensorPolynomial(const UTensorPolynomial &up)
-  : TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(up.nrows(), up.nvars())
+FTensorPolynomial::FTensorPolynomial(const UTensorPolynomial& up) :
+    TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(up.nrows(), up.nvars())
 {
-  for (const auto &it : up)
+  for (const auto& it : up)
     insert(std::make_unique<FFSTensor>(*(it.second)));
 }
diff --git a/mex/sources/libkorder/tl/t_polynomial.hh b/mex/sources/libkorder/tl/t_polynomial.hh
index 3c87d5d9a74fa672b30fef58da1339f03c613f8f..545cf435ad0601a1d28562808ffcfa4e122027dd 100644
--- a/mex/sources/libkorder/tl/t_polynomial.hh
+++ b/mex/sources/libkorder/tl/t_polynomial.hh
@@ -51,11 +51,11 @@
    compactification of the polynomial. The class derives from the tensor
    and has a eval method. */
 
-#include "t_container.hh"
 #include "fs_tensor.hh"
+#include "pascal_triangle.hh"
 #include "rfs_tensor.hh"
+#include "t_container.hh"
 #include "tl_static.hh"
-#include "pascal_triangle.hh"
 
 #include <memory>
 
@@ -80,9 +80,9 @@ class PowerProvider
   std::unique_ptr<URSingleTensor> ut;
   std::unique_ptr<FRSingleTensor> ft;
   int nv;
+
 public:
-  PowerProvider(const ConstVector &v)
-    : origv(v), nv(v.length())
+  PowerProvider(const ConstVector& v) : origv(v), nv(v.length())
   {
   }
 
@@ -98,18 +98,21 @@ public:
     https://stackoverflow.com/questions/3052579/explicit-specialization-in-non-namespace-scope
   */
   template<typename T>
-  struct dummy { using type = T; };
+  struct dummy
+  {
+    using type = T;
+  };
 
   template<class T>
-  const T &
+  const T&
   getNext()
   {
     return getNext(dummy<T>());
   }
 
 private:
-  const URSingleTensor &getNext(dummy<URSingleTensor>);
-  const FRSingleTensor &getNext(dummy<FRSingleTensor>);
+  const URSingleTensor& getNext(dummy<URSingleTensor>);
+  const FRSingleTensor& getNext(dummy<FRSingleTensor>);
 };
 
 /* The tensor polynomial is basically a tensor container which is more
@@ -136,21 +139,18 @@ class TensorPolynomial : public TensorContainer<_Ttype>
   int nv;
   int maxdim;
   using _Tparent = TensorContainer<_Ttype>;
+
 public:
-  TensorPolynomial(int rows, int vars)
-    : TensorContainer<_Ttype>(1),
-      nr(rows), nv(vars), maxdim(0)
+  TensorPolynomial(int rows, int vars) : TensorContainer<_Ttype>(1), nr(rows), nv(vars), maxdim(0)
   {
   }
-  TensorPolynomial(const TensorPolynomial<_Ttype, _TGStype, _Stype> &tp, int k)
-    : TensorContainer<_Ttype>(tp),
-      nr(tp.nr), nv(tp.nv), maxdim(0)
+  TensorPolynomial(const TensorPolynomial<_Ttype, _TGStype, _Stype>& tp, int k) :
+      TensorContainer<_Ttype>(tp), nr(tp.nr), nv(tp.nv), maxdim(0)
   {
     derivative(k);
   }
-  TensorPolynomial(int first_row, int num, TensorPolynomial<_Ttype, _TGStype, _Stype> &tp)
-    : TensorContainer<_Ttype>(first_row, num, tp),
-      nr(num), nv(tp.nv), maxdim(tp.maxdim)
+  TensorPolynomial(int first_row, int num, TensorPolynomial<_Ttype, _TGStype, _Stype>& tp) :
+      TensorContainer<_Ttype>(first_row, num, tp), nr(num), nv(tp.nv), maxdim(tp.maxdim)
   {
   }
 
@@ -175,14 +175,12 @@ public:
      symmetry of the slice to obtain stack coordinates of the slice. Then we do
      the calculations for i=1,…,m and then for i=0. */
 
-  TensorPolynomial(const TensorPolynomial<_Ttype, _TGStype, _Stype> &tp, const Vector &xval)
-    : TensorContainer<_Ttype>(1),
-      nr(tp.nrows()), nv(tp.nvars() - xval.length()), maxdim(0)
+  TensorPolynomial(const TensorPolynomial<_Ttype, _TGStype, _Stype>& tp, const Vector& xval) :
+      TensorContainer<_Ttype>(1), nr(tp.nrows()), nv(tp.nvars() - xval.length()), maxdim(0)
   {
-    TL_RAISE_IF(nvars() < 0,
-                "Length of xval too big in TensorPolynomial contract constructor");
-    IntSequence ss{xval.length(), nvars()};
-    IntSequence pp{0, 1};
+    TL_RAISE_IF(nvars() < 0, "Length of xval too big in TensorPolynomial contract constructor");
+    IntSequence ss {xval.length(), nvars()};
+    IntSequence pp {0, 1};
 
     // do contraction for all i>0
     /* Here we setup the PowerProvider, and cycle through i=1,…,m. Within the
@@ -204,15 +202,15 @@ public:
     PowerProvider pwp(xval);
     for (int i = 1; i <= tp.maxdim; i++)
       {
-        const _Stype &xpow = pwp.getNext<_Stype>();
-        for (int j = 0; j <= tp.maxdim-i; j++)
-          if (tp.check(Symmetry{i+j}))
+        const _Stype& xpow = pwp.getNext<_Stype>();
+        for (int j = 0; j <= tp.maxdim - i; j++)
+          if (tp.check(Symmetry {i + j}))
             {
               // initialize ‘ten’ of dimension ‘j’
               /* The pointer ‘ten’ is either a new tensor or got from ‘this’ container. */
-              _Ttype *ten;
-              if (_Tparent::check(Symmetry{j}))
-                ten = &_Tparent::get(Symmetry{j});
+              _Ttype* ten;
+              if (_Tparent::check(Symmetry {j}))
+                ten = &_Tparent::get(Symmetry {j});
               else
                 {
                   auto ten_smart = std::make_unique<_Ttype>(nrows(), nvars(), j);
@@ -221,10 +219,10 @@ public:
                   insert(std::move(ten_smart));
                 }
 
-              Symmetry sym{i, j};
+              Symmetry sym {i, j};
               IntSequence coor(pp.unfold(sym));
-              _TGStype slice(tp.get(Symmetry{i+j}), ss, coor, TensorDimens(sym, ss));
-              slice.mult(PascalTriangle::noverk(i+j, j));
+              _TGStype slice(tp.get(Symmetry {i + j}), ss, coor, TensorDimens(sym, ss));
+              slice.mult(PascalTriangle::noverk(i + j, j));
               _TGStype tmp(*ten);
               slice.contractAndAdd(0, tmp, xpow);
             }
@@ -234,14 +232,14 @@ public:
     /* This is easy. The code is equivalent to “do contraction for all i>0” as
        for i=0. The contraction here takes a form of a simple addition. */
     for (int j = 0; j <= tp.maxdim; j++)
-      if (tp.check(Symmetry{j}))
+      if (tp.check(Symmetry {j}))
         {
 
           // initialize ‘ten’ of dimension ‘j’
           /* Same code as above */
-          _Ttype *ten;
-          if (_Tparent::check(Symmetry{j}))
-            ten = &_Tparent::get(Symmetry{j});
+          _Ttype* ten;
+          if (_Tparent::check(Symmetry {j}))
+            ten = &_Tparent::get(Symmetry {j});
           else
             {
               auto ten_smart = std::make_unique<_Ttype>(nrows(), nvars(), j);
@@ -250,15 +248,15 @@ public:
               insert(std::move(ten_smart));
             }
 
-          Symmetry sym{0, j};
+          Symmetry sym {0, j};
           IntSequence coor(pp.unfold(sym));
-          _TGStype slice(tp.get(Symmetry{j}), ss, coor, TensorDimens(sym, ss));
+          _TGStype slice(tp.get(Symmetry {j}), ss, coor, TensorDimens(sym, ss));
           ten->add(1.0, slice);
         }
   }
 
-  TensorPolynomial(const TensorPolynomial &tp)
-    : TensorContainer<_Ttype>(tp), nr(tp.nr), nv(tp.nv), maxdim(tp.maxdim)
+  TensorPolynomial(const TensorPolynomial& tp) :
+      TensorContainer<_Ttype>(tp), nr(tp.nr), nv(tp.nv), maxdim(tp.maxdim)
   {
   }
   int
@@ -277,21 +275,21 @@ public:
      vector supplied by PowerProvider. */
 
   void
-  evalTrad(Vector &out, const ConstVector &v) const
+  evalTrad(Vector& out, const ConstVector& v) const
   {
-    if (_Tparent::check(Symmetry{0}))
-      out = _Tparent::get(Symmetry{0}).getData();
+    if (_Tparent::check(Symmetry {0}))
+      out = _Tparent::get(Symmetry {0}).getData();
     else
       out.zeros();
 
     PowerProvider pp(v);
     for (int d = 1; d <= maxdim; d++)
       {
-        const _Stype &p = pp.getNext<_Stype>();
-        Symmetry cs{d};
+        const _Stype& p = pp.getNext<_Stype>();
+        Symmetry cs {d};
         if (_Tparent::check(cs))
           {
-            const _Ttype &t = _Tparent::get(cs);
+            const _Ttype& t = _Tparent::get(cs);
             t.multaVec(out, p.getData());
           }
       }
@@ -301,10 +299,10 @@ public:
      cycle. */
 
   void
-  evalHorner(Vector &out, const ConstVector &v) const
+  evalHorner(Vector& out, const ConstVector& v) const
   {
-    if (_Tparent::check(Symmetry{0}))
-      out = _Tparent::get(Symmetry{0}).getData();
+    if (_Tparent::check(Symmetry {0}))
+      out = _Tparent::get(Symmetry {0}).getData();
     else
       out.zeros();
 
@@ -313,15 +311,14 @@ public:
 
     std::unique_ptr<_Ttype> last;
     if (maxdim == 1)
-      last = std::make_unique<_Ttype>(_Tparent::get(Symmetry{1}));
+      last = std::make_unique<_Ttype>(_Tparent::get(Symmetry {1}));
     else
-      last = std::make_unique<_Ttype>(_Tparent::get(Symmetry{maxdim}), v);
-    for (int d = maxdim-1; d >= 1; d--)
+      last = std::make_unique<_Ttype>(_Tparent::get(Symmetry {maxdim}), v);
+    for (int d = maxdim - 1; d >= 1; d--)
       {
-        if (Symmetry cs{d};
-            _Tparent::check(cs))
+        if (Symmetry cs {d}; _Tparent::check(cs))
           {
-            const _Ttype &nt = _Tparent::get(cs);
+            const _Ttype& nt = _Tparent::get(cs);
             last->add(1.0, ConstTwoDMatrix(nt));
           }
         if (d > 1)
@@ -336,10 +333,8 @@ public:
   void
   insert(std::unique_ptr<_Ttype> t) override
   {
-    TL_RAISE_IF(t->nrows() != nr,
-                "Wrong number of rows in TensorPolynomial::insert");
-    TL_RAISE_IF(t->nvar() != nv,
-                "Wrong number of variables in TensorPolynomial::insert");
+    TL_RAISE_IF(t->nrows() != nr, "Wrong number of rows in TensorPolynomial::insert");
+    TL_RAISE_IF(t->nvar() != nv, "Wrong number of variables in TensorPolynomial::insert");
     if (maxdim < t->dimen())
       maxdim = t->dimen();
     TensorContainer<_Ttype>::insert(std::move(t));
@@ -368,10 +363,10 @@ public:
   derivative(int k)
   {
     for (int d = 1; d <= maxdim; d++)
-      if (_Tparent::check(Symmetry{d}))
+      if (_Tparent::check(Symmetry {d}))
         {
-          _Ttype &ten = _Tparent::get(Symmetry{d});
-          ten.mult(static_cast<double>(std::max((d-k), 0)));
+          _Ttype& ten = _Tparent::get(Symmetry {d});
+          ten.mult(static_cast<double>(std::max((d - k), 0)));
         }
   }
 
@@ -392,7 +387,7 @@ public:
      calculates 2! multiple of the second derivative of g at v. */
 
   std::unique_ptr<_Ttype>
-  evalPartially(int s, const ConstVector &v)
+  evalPartially(int s, const ConstVector& v)
   {
     TL_RAISE_IF(v.length() != nvars(),
                 "Wrong length of vector for TensorPolynomial::evalPartially");
@@ -400,13 +395,13 @@ public:
     auto res = std::make_unique<_Ttype>(nrows(), nvars(), s);
     res->zeros();
 
-    if (_Tparent::check(Symmetry{s}))
-      res->add(1.0, _Tparent::get(Symmetry{s}));
+    if (_Tparent::check(Symmetry {s}))
+      res->add(1.0, _Tparent::get(Symmetry {s}));
 
-    for (int d = s+1; d <= maxdim; d++)
-      if (_Tparent::check(Symmetry{d}))
+    for (int d = s + 1; d <= maxdim; d++)
+      if (_Tparent::check(Symmetry {d}))
         {
-          const _Ttype &ltmp = _Tparent::get(Symmetry{d});
+          const _Ttype& ltmp = _Tparent::get(Symmetry {d});
           auto last = std::make_unique<_Ttype>(ltmp);
           for (int j = 0; j < d - s; j++)
             {
@@ -426,21 +421,21 @@ class FTensorPolynomial;
 class UTensorPolynomial : public TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>
 {
 public:
-  UTensorPolynomial(int rows, int vars)
-    : TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>(rows, vars)
+  UTensorPolynomial(int rows, int vars) :
+      TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>(rows, vars)
   {
   }
-  UTensorPolynomial(const UTensorPolynomial &up, int k)
-    : TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>(up, k)
+  UTensorPolynomial(const UTensorPolynomial& up, int k) :
+      TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>(up, k)
   {
   }
-  UTensorPolynomial(const FTensorPolynomial &fp);
-  UTensorPolynomial(const UTensorPolynomial &tp, const Vector &xval)
-    : TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>(tp, xval)
+  UTensorPolynomial(const FTensorPolynomial& fp);
+  UTensorPolynomial(const UTensorPolynomial& tp, const Vector& xval) :
+      TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>(tp, xval)
   {
   }
-  UTensorPolynomial(int first_row, int num, UTensorPolynomial &tp)
-    : TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>(first_row, num, tp)
+  UTensorPolynomial(int first_row, int num, UTensorPolynomial& tp) :
+      TensorPolynomial<UFSTensor, UGSTensor, URSingleTensor>(first_row, num, tp)
   {
   }
 };
@@ -450,21 +445,21 @@ public:
 class FTensorPolynomial : public TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>
 {
 public:
-  FTensorPolynomial(int rows, int vars)
-    : TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(rows, vars)
+  FTensorPolynomial(int rows, int vars) :
+      TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(rows, vars)
   {
   }
-  FTensorPolynomial(const FTensorPolynomial &fp, int k)
-    : TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(fp, k)
+  FTensorPolynomial(const FTensorPolynomial& fp, int k) :
+      TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(fp, k)
   {
   }
-  FTensorPolynomial(const UTensorPolynomial &up);
-  FTensorPolynomial(const FTensorPolynomial &tp, const Vector &xval)
-    : TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(tp, xval)
+  FTensorPolynomial(const UTensorPolynomial& up);
+  FTensorPolynomial(const FTensorPolynomial& tp, const Vector& xval) :
+      TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(tp, xval)
   {
   }
-  FTensorPolynomial(int first_row, int num, FTensorPolynomial &tp)
-    : TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(first_row, num, tp)
+  FTensorPolynomial(int first_row, int num, FTensorPolynomial& tp) :
+      TensorPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(first_row, num, tp)
   {
   }
 };
@@ -488,24 +483,24 @@ public:
      index. We then copy the matrix, if it exists in the polynomial and
      increase ‘offset’ for the following cycle. */
 
-  CompactPolynomial(const TensorPolynomial<_Ttype, _TGStype, _Stype> &pol)
-    : _Ttype(pol.nrows(), pol.nvars()+1, pol.getMaxDim())
+  CompactPolynomial(const TensorPolynomial<_Ttype, _TGStype, _Stype>& pol) :
+      _Ttype(pol.nrows(), pol.nvars() + 1, pol.getMaxDim())
   {
     _Ttype::zeros();
 
-    IntSequence dumnvs{1, pol.nvars()};
+    IntSequence dumnvs {1, pol.nvars()};
 
     int offset = 0;
     _Ttype dum(0, 2, _Ttype::dimen());
     for (Tensor::index i = dum.begin(); i != dum.end(); ++i)
       {
         int d = i.getCoor().sum();
-        Symmetry symrun{_Ttype::dimen()-d, d};
+        Symmetry symrun {_Ttype::dimen() - d, d};
         _TGStype dumgs(0, TensorDimens(symrun, dumnvs));
-        if (pol.check(Symmetry{d}))
+        if (pol.check(Symmetry {d}))
           {
             TwoDMatrix subt(*this, offset, dumgs.ncols());
-            subt.add(1.0, pol.get(Symmetry{d}));
+            subt.add(1.0, pol.get(Symmetry {d}));
           }
         offset += dumgs.ncols();
       }
@@ -516,14 +511,14 @@ public:
      multiply this matrix with the power. */
 
   void
-  eval(Vector &out, const ConstVector &v) const
+  eval(Vector& out, const ConstVector& v) const
   {
-    TL_RAISE_IF(v.length()+1 != _Ttype::nvar(),
+    TL_RAISE_IF(v.length() + 1 != _Ttype::nvar(),
                 "Wrong input vector length in CompactPolynomial::eval");
     TL_RAISE_IF(out.length() != _Ttype::nrows(),
                 "Wrong output vector length in CompactPolynomial::eval");
 
-    Vector x1(v.length()+1);
+    Vector x1(v.length() + 1);
     Vector x1p(x1, 1, v.length());
     x1p = v;
     x1[0] = 1.0;
@@ -533,7 +528,7 @@ public:
     else
       {
         PowerProvider pp(x1);
-        const _Stype &xpow = pp.getNext<_Stype>();
+        const _Stype& xpow = pp.getNext<_Stype>();
         for (int i = 1; i < _Ttype::dimen(); i++)
           xpow = pp.getNext<_Stype>();
         multVec(0.0, out, 1.0, xpow);
@@ -545,8 +540,8 @@ public:
 class UCompactPolynomial : public CompactPolynomial<UFSTensor, UGSTensor, URSingleTensor>
 {
 public:
-  UCompactPolynomial(const UTensorPolynomial &upol)
-    : CompactPolynomial<UFSTensor, UGSTensor, URSingleTensor>(upol)
+  UCompactPolynomial(const UTensorPolynomial& upol) :
+      CompactPolynomial<UFSTensor, UGSTensor, URSingleTensor>(upol)
   {
   }
 };
@@ -555,8 +550,8 @@ public:
 class FCompactPolynomial : public CompactPolynomial<FFSTensor, FGSTensor, FRSingleTensor>
 {
 public:
-  FCompactPolynomial(const FTensorPolynomial &fpol)
-    : CompactPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(fpol)
+  FCompactPolynomial(const FTensorPolynomial& fpol) :
+      CompactPolynomial<FFSTensor, FGSTensor, FRSingleTensor>(fpol)
   {
   }
 };
diff --git a/mex/sources/libkorder/tl/tensor.cc b/mex/sources/libkorder/tl/tensor.cc
index 425d3932dff83b4707fc354562ecf0daf1c6d705..13e3efa4fcef446eeeff11bf352721d9cfc72d32 100644
--- a/mex/sources/libkorder/tl/tensor.cc
+++ b/mex/sources/libkorder/tl/tensor.cc
@@ -19,9 +19,9 @@
  */
 
 #include "tensor.hh"
+#include "pascal_triangle.hh"
 #include "tl_exception.hh"
 #include "tl_static.hh"
-#include "pascal_triangle.hh"
 
 /* Here we increment a given sequence within full symmetry given by ‘nv’, which
    is number of variables in each dimension. The underlying tensor is unfolded,
@@ -29,11 +29,11 @@
    increase the next one to the left. */
 
 void
-UTensor::increment(IntSequence &v, int nv)
+UTensor::increment(IntSequence& v, int nv)
 {
   if (v.size() == 0)
     return;
-  int i = v.size()-1;
+  int i = v.size() - 1;
   v[i]++;
   while (i > 0 && v[i] == nv)
     {
@@ -45,15 +45,15 @@ UTensor::increment(IntSequence &v, int nv)
 /* This is dual to UTensor::increment(IntSequence& v, int nv). */
 
 void
-UTensor::decrement(IntSequence &v, int nv)
+UTensor::decrement(IntSequence& v, int nv)
 {
   if (v.size() == 0)
     return;
-  int i = v.size()-1;
+  int i = v.size() - 1;
   v[i]--;
   while (i > 0 && v[i] == -1)
     {
-      v[i] = nv -1;
+      v[i] = nv - 1;
       v[--i]--;
     }
 }
@@ -64,11 +64,11 @@ UTensor::decrement(IntSequence &v, int nv)
    symmetric, everything necessary is given by ‘nvmx’. */
 
 void
-UTensor::increment(IntSequence &v, const IntSequence &nvmx)
+UTensor::increment(IntSequence& v, const IntSequence& nvmx)
 {
   if (v.size() == 0)
     return;
-  int i = v.size()-1;
+  int i = v.size() - 1;
   v[i]++;
   while (i > 0 && v[i] == nvmx[i])
     {
@@ -81,15 +81,15 @@ UTensor::increment(IntSequence &v, const IntSequence &nvmx)
    nvmx). */
 
 void
-UTensor::decrement(IntSequence &v, const IntSequence &nvmx)
+UTensor::decrement(IntSequence& v, const IntSequence& nvmx)
 {
   if (v.size() == 0)
     return;
-  int i = v.size()-1;
+  int i = v.size() - 1;
   v[i]--;
   while (i > 0 && v[i] == -1)
     {
-      v[i] = nvmx[i] -1;
+      v[i] = nvmx[i] - 1;
       v[--i]--;
     }
 }
@@ -98,7 +98,7 @@ UTensor::decrement(IntSequence &v, const IntSequence &nvmx)
    tensor. This is easy. */
 
 int
-UTensor::getOffset(const IntSequence &v, int nv)
+UTensor::getOffset(const IntSequence& v, int nv)
 {
   int res = 0;
   for (int i = 0; i < v.size(); i++)
@@ -112,7 +112,7 @@ UTensor::getOffset(const IntSequence &v, int nv)
 /* Also easy. */
 
 int
-UTensor::getOffset(const IntSequence &v, const IntSequence &nvmx)
+UTensor::getOffset(const IntSequence& v, const IntSequence& nvmx)
 {
   int res = 0;
   for (int i = 0; i < v.size(); i++)
@@ -130,14 +130,14 @@ UTensor::getOffset(const IntSequence &v, const IntSequence &nvmx)
    decrease it by one, and then set all elements to the right to n−1. */
 
 void
-FTensor::decrement(IntSequence &v, int nv)
+FTensor::decrement(IntSequence& v, int nv)
 {
-  int i = v.size()-1;
-  while (i > 0 && v[i-1] == v[i])
+  int i = v.size() - 1;
+  while (i > 0 && v[i - 1] == v[i])
     i--;
   v[i]--;
-  for (int j = i+1; j < v.size(); j++)
-    v[j] = nv-1;
+  for (int j = i + 1; j < v.size(); j++)
+    v[j] = nv - 1;
 }
 
 /* This calculates order of the given index of our ordering of indices. In
@@ -181,16 +181,16 @@ FTensor::decrement(IntSequence &v, int nv)
    (m₂−m₁,m₃−m₁,…,mₖ−m₁) for n−m₁ variables. */
 
 int
-FTensor::getOffsetRecurse(IntSequence &v, int nv)
+FTensor::getOffsetRecurse(IntSequence& v, int nv)
 {
   if (v.size() == 0)
     return 0;
   int prefix = v.getPrefixLength();
   int m = v[0];
   int k = v.size();
-  int s1 = PascalTriangle::noverk(nv+k-1, k) - PascalTriangle::noverk(nv-m+k-1, k);
+  int s1 = PascalTriangle::noverk(nv + k - 1, k) - PascalTriangle::noverk(nv - m + k - 1, k);
   IntSequence subv(v, prefix, k);
   subv.add(-m);
-  int s2 = getOffsetRecurse(subv, nv-m);
-  return s1+s2;
+  int s2 = getOffsetRecurse(subv, nv - m);
+  return s1 + s2;
 }
diff --git a/mex/sources/libkorder/tl/tensor.hh b/mex/sources/libkorder/tl/tensor.hh
index 0d4150394144f084896eea463a4e366c628a1e97..cc4506636130a1960769a5fc174bad46986fe7c7 100644
--- a/mex/sources/libkorder/tl/tensor.hh
+++ b/mex/sources/libkorder/tl/tensor.hh
@@ -63,8 +63,8 @@
 #include "int_sequence.hh"
 #include "twod_matrix.hh"
 
-#include <memory>
 #include <iostream>
+#include <memory>
 
 /* Here is the Tensor class, which is nothing else than a simple subclass of
    TwoDMatrix. The unique semantically new member is ‘dim’ which is tensor
@@ -83,7 +83,11 @@
 class Tensor : public TwoDMatrix
 {
 public:
-  enum class indor { along_row, along_col };
+  enum class indor
+  {
+    along_row,
+    along_col
+  };
 
   /* The index represents n-tuple α₁…αₙ. Since its movement is dependent on the
      underlying tensor (with storage and symmetry), we maintain a reference to
@@ -108,34 +112,33 @@ public:
      representations of past-the-end index. */
   class index
   {
-    const Tensor &tensor;
+    const Tensor& tensor;
     int offset;
     IntSequence coor;
+
   public:
-    index(const Tensor &t, int n)
-      : tensor(t), offset(0), coor(n, 0)
+    index(const Tensor& t, int n) : tensor(t), offset(0), coor(n, 0)
     {
     }
-    index(const Tensor &t, IntSequence cr, int c)
-      : tensor(t), offset(c), coor(std::move(cr))
+    index(const Tensor& t, IntSequence cr, int c) : tensor(t), offset(c), coor(std::move(cr))
     {
     }
-    index(const Tensor &t, IntSequence cr)
-      : tensor(t), offset(tensor.getOffset(cr)), coor(std::move(cr))
+    index(const Tensor& t, IntSequence cr) :
+        tensor(t), offset(tensor.getOffset(cr)), coor(std::move(cr))
     {
     }
-    index(const index &) = default;
-    index(index &&) = default;
-    index &operator=(const index &) = delete;
-    index &operator=(index &&) = delete;
-    index &
+    index(const index&) = default;
+    index(index&&) = default;
+    index& operator=(const index&) = delete;
+    index& operator=(index&&) = delete;
+    index&
     operator++()
     {
       tensor.increment(coor);
       offset++;
       return *this;
     }
-    index &
+    index&
     operator--()
     {
       tensor.decrement(coor);
@@ -148,16 +151,16 @@ public:
       return offset;
     }
     bool
-    operator==(const index &n) const
+    operator==(const index& n) const
     {
       return offset == n.offset;
     }
     bool
-    operator!=(const index &n) const
+    operator!=(const index& n) const
     {
       return offset != n.offset;
     }
-    const IntSequence &
+    const IntSequence&
     getCoor() const
     {
       return coor;
@@ -174,57 +177,48 @@ protected:
   const index in_beg;
   const index in_end;
   int dim;
+
 public:
-  Tensor(indor io, IntSequence last, int r, int c, int d)
-    : TwoDMatrix(r, c),
-      in_beg(*this, d),
-      in_end(*this, std::move(last), (io == indor::along_row) ? r : c),
-      dim(d)
+  Tensor(indor io, IntSequence last, int r, int c, int d) :
+      TwoDMatrix(r, c), in_beg(*this, d),
+      in_end(*this, std::move(last), (io == indor::along_row) ? r : c), dim(d)
   {
   }
-  Tensor(indor io, IntSequence first, IntSequence last,
-         int r, int c, int d)
-    : TwoDMatrix(r, c),
-      in_beg(*this, std::move(first), 0),
-      in_end(*this, std::move(last), (io == indor::along_row) ? r : c),
-      dim(d)
+  Tensor(indor io, IntSequence first, IntSequence last, int r, int c, int d) :
+      TwoDMatrix(r, c), in_beg(*this, std::move(first), 0),
+      in_end(*this, std::move(last), (io == indor::along_row) ? r : c), dim(d)
   {
   }
-  Tensor(int first_row, int num, Tensor &t)
-    : TwoDMatrix(first_row, num, t),
-      in_beg(t.in_beg),
-      in_end(t.in_end),
-      dim(t.dim)
+  Tensor(int first_row, int num, Tensor& t) :
+      TwoDMatrix(first_row, num, t), in_beg(t.in_beg), in_end(t.in_end), dim(t.dim)
   {
   }
-  Tensor(const Tensor &t)
-    : TwoDMatrix(t),
-      in_beg(*this, t.in_beg.getCoor(), *(t.in_beg)),
-      in_end(*this, t.in_end.getCoor(), *(t.in_end)),
-      dim(t.dim)
+  Tensor(const Tensor& t) :
+      TwoDMatrix(t), in_beg(*this, t.in_beg.getCoor(), *(t.in_beg)),
+      in_end(*this, t.in_end.getCoor(), *(t.in_end)), dim(t.dim)
   {
   }
-  Tensor(Tensor &&) = default;
+  Tensor(Tensor&&) = default;
   ~Tensor() override = default;
 
-  Tensor &operator=(const Tensor &) = delete;
-  Tensor &operator=(Tensor &&) = delete;
+  Tensor& operator=(const Tensor&) = delete;
+  Tensor& operator=(Tensor&&) = delete;
 
-  virtual void increment(IntSequence &v) const = 0;
-  virtual void decrement(IntSequence &v) const = 0;
-  virtual int getOffset(const IntSequence &v) const = 0;
+  virtual void increment(IntSequence& v) const = 0;
+  virtual void decrement(IntSequence& v) const = 0;
+  virtual int getOffset(const IntSequence& v) const = 0;
   int
   dimen() const
   {
     return dim;
   }
 
-  const index &
+  const index&
   begin() const
   {
     return in_beg;
   }
-  const index &
+  const index&
   end() const
   {
     return in_end;
@@ -240,33 +234,31 @@ class FTensor;
 class UTensor : public Tensor
 {
 public:
-  UTensor(indor io, IntSequence last, int r, int c, int d)
-    : Tensor(io, std::move(last), r, c, d)
+  UTensor(indor io, IntSequence last, int r, int c, int d) : Tensor(io, std::move(last), r, c, d)
   {
   }
-  UTensor(const UTensor &) = default;
-  UTensor(UTensor &&) = default;
-  UTensor(int first_row, int num, UTensor &t)
-    : Tensor(first_row, num, t)
+  UTensor(const UTensor&) = default;
+  UTensor(UTensor&&) = default;
+  UTensor(int first_row, int num, UTensor& t) : Tensor(first_row, num, t)
   {
   }
   ~UTensor() override = default;
   virtual std::unique_ptr<FTensor> fold() const = 0;
 
-  UTensor &operator=(const UTensor &) = delete;
-  UTensor &operator=(UTensor &&) = delete;
+  UTensor& operator=(const UTensor&) = delete;
+  UTensor& operator=(UTensor&&) = delete;
 
   // Ensure that the methods of the parent class are not overloaded
-  using Tensor::increment;
   using Tensor::decrement;
   using Tensor::getOffset;
+  using Tensor::increment;
 
-  static void increment(IntSequence &v, int nv);
-  static void decrement(IntSequence &v, int nv);
-  static void increment(IntSequence &v, const IntSequence &nvmx);
-  static void decrement(IntSequence &v, const IntSequence &nvmx);
-  static int getOffset(const IntSequence &v, int nv);
-  static int getOffset(const IntSequence &v, const IntSequence &nvmx);
+  static void increment(IntSequence& v, int nv);
+  static void decrement(IntSequence& v, int nv);
+  static void increment(IntSequence& v, const IntSequence& nvmx);
+  static void decrement(IntSequence& v, const IntSequence& nvmx);
+  static int getOffset(const IntSequence& v, int nv);
+  static int getOffset(const IntSequence& v, const IntSequence& nvmx);
 };
 
 /* This is an abstraction for folded tensor. It only provides a method
@@ -281,35 +273,34 @@ public:
 class FTensor : public Tensor
 {
 public:
-  FTensor(indor io, IntSequence last, int r, int c, int d)
-    : Tensor(io, std::move(last), r, c, d)
+  FTensor(indor io, IntSequence last, int r, int c, int d) : Tensor(io, std::move(last), r, c, d)
   {
   }
-  FTensor(const FTensor &) = default;
-  FTensor(FTensor &&) = default;
-  FTensor(int first_row, int num, FTensor &t)
-    : Tensor(first_row, num, t)
+  FTensor(const FTensor&) = default;
+  FTensor(FTensor&&) = default;
+  FTensor(int first_row, int num, FTensor& t) : Tensor(first_row, num, t)
   {
   }
   ~FTensor() override = default;
   virtual std::unique_ptr<UTensor> unfold() const = 0;
 
-  FTensor &operator=(const FTensor &) = delete;
-  FTensor &operator=(FTensor &&) = delete;
+  FTensor& operator=(const FTensor&) = delete;
+  FTensor& operator=(FTensor&&) = delete;
 
   // Ensure that the methods of the parent class are not overloaded
   using Tensor::decrement;
   using Tensor::getOffset;
 
-  static void decrement(IntSequence &v, int nv);
+  static void decrement(IntSequence& v, int nv);
   static int
-  getOffset(const IntSequence &v, int nv)
+  getOffset(const IntSequence& v, int nv)
   {
     IntSequence vtmp(v);
     return getOffsetRecurse(vtmp, nv);
   }
+
 private:
-  static int getOffsetRecurse(IntSequence &v, int nv);
+  static int getOffsetRecurse(IntSequence& v, int nv);
 };
 
 #endif
diff --git a/mex/sources/libkorder/tl/tests/factory.cc b/mex/sources/libkorder/tl/tests/factory.cc
index 589c3824a4617a80c4fcf9d1dad013bca96c54a9..95b504816bf775441340fffd8fce8c0c602055fd 100644
--- a/mex/sources/libkorder/tl/tests/factory.cc
+++ b/mex/sources/libkorder/tl/tests/factory.cc
@@ -21,15 +21,15 @@
 #include "factory.hh"
 
 void
-Factory::init(const Symmetry &s, const IntSequence &nvs)
+Factory::init(const Symmetry& s, const IntSequence& nvs)
 {
   IntSequence sym(s);
   decltype(mtgen)::result_type seed = sym[0];
-  seed = 256*seed + nvs[0];
+  seed = 256 * seed + nvs[0];
   if (sym.size() > 1)
-    seed = 256*seed + sym[1];
+    seed = 256 * seed + sym[1];
   if (nvs.size() > 1)
-    seed = 256*seed + nvs[0];
+    seed = 256 * seed + nvs[0];
   mtgen.seed(seed);
 }
 
@@ -37,20 +37,20 @@ void
 Factory::init(int dim, int nv)
 {
   decltype(mtgen)::result_type seed = dim;
-  seed = 256*seed + nv;
+  seed = 256 * seed + nv;
   mtgen.seed(seed);
 }
 
 double
 Factory::get()
 {
-  return dis(mtgen)-0.5;
+  return dis(mtgen) - 0.5;
 }
 
 void
-Factory::fillMatrix(TwoDMatrix &m)
+Factory::fillMatrix(TwoDMatrix& m)
 {
-  Vector &d = m.getData();
+  Vector& d = m.getData();
   for (int i = 0; i < d.length(); i++)
     d[i] = get();
 }
@@ -58,7 +58,7 @@ Factory::fillMatrix(TwoDMatrix &m)
 Vector
 Factory::makeVector(int n)
 {
-  init(n, n*n);
+  init(n, n * n);
 
   Vector v(n);
   for (int i = 0; i < n; i++)
diff --git a/mex/sources/libkorder/tl/tests/factory.hh b/mex/sources/libkorder/tl/tests/factory.hh
index bedefb71b59ff1ff52c033180d07aea1509fdba6..b369c2404b8ce0b25883becbd31a3eaaea7ae11e 100644
--- a/mex/sources/libkorder/tl/tests/factory.hh
+++ b/mex/sources/libkorder/tl/tests/factory.hh
@@ -21,30 +21,31 @@
 #ifndef FACTORY_H
 #define FACTORY_H
 
-#include <random>
 #include <memory>
+#include <random>
 
-#include "symmetry.hh"
-#include "int_sequence.hh"
-#include "twod_matrix.hh"
 #include "equivalence.hh"
+#include "int_sequence.hh"
 #include "rfs_tensor.hh"
+#include "symmetry.hh"
 #include "t_container.hh"
+#include "twod_matrix.hh"
 
 class Factory
 {
   std::mt19937 mtgen;
   std::uniform_real_distribution<> dis;
 
-  void init(const Symmetry &s, const IntSequence &nvs);
+  void init(const Symmetry& s, const IntSequence& nvs);
   void init(int dim, int nv);
-  void fillMatrix(TwoDMatrix &m);
+  void fillMatrix(TwoDMatrix& m);
+
 public:
   double get();
   // This can be used with UGSTensor, FGSTensor
   template<class _Ttype>
   std::unique_ptr<_Ttype>
-  make(int r, const Symmetry &s, const IntSequence &nvs)
+  make(int r, const Symmetry& s, const IntSequence& nvs)
   {
     auto res = std::make_unique<_Ttype>(r, TensorDimens(s, nvs));
     init(s, nvs);
@@ -65,18 +66,18 @@ public:
 
   template<class _Ttype, class _Ctype>
   _Ctype
-  makeCont(int r, const IntSequence &nvs, int maxdim)
+  makeCont(int r, const IntSequence& nvs, int maxdim)
   {
     int symnum = nvs.size();
     _Ctype res(symnum);
     for (int dim = 1; dim <= maxdim; dim++)
       if (symnum == 1)
         // Full symmetry
-        res.insert(make<_Ttype>(r, Symmetry{dim}, nvs));
+        res.insert(make<_Ttype>(r, Symmetry {dim}, nvs));
       else
         // General symmetry
         for (int i = 0; i <= dim; i++)
-          res.insert(make<_Ttype>(r, Symmetry{i, dim-i}, nvs));
+          res.insert(make<_Ttype>(r, Symmetry {i, dim - i}, nvs));
     return res;
   }
 
diff --git a/mex/sources/libkorder/tl/tests/monoms.cc b/mex/sources/libkorder/tl/tests/monoms.cc
index 4623c319e91f4c2096d7c705d50f9316bd07bfa5..547ec250fcc8e8d98a24e11f447a99594c4bbbe0 100644
--- a/mex/sources/libkorder/tl/tests/monoms.cc
+++ b/mex/sources/libkorder/tl/tests/monoms.cc
@@ -19,24 +19,23 @@
  */
 
 #include "monoms.hh"
-#include "tl_exception.hh"
 #include "fs_tensor.hh"
+#include "tl_exception.hh"
 
 #include <iostream>
 
 IntGenerator intgen;
 
 void
-IntGenerator::init(int nf, int ny, int nv, int nw, int nu,
-                   int mx, double prob)
+IntGenerator::init(int nf, int ny, int nv, int nw, int nu, int mx, double prob)
 {
   maxim = mx;
   probab = prob;
   decltype(mtgen)::result_type seed = nf;
-  seed = 256*seed + ny;
-  seed = 256*seed + nv;
-  seed = 256*seed + nw;
-  seed = 256*seed + nu;
+  seed = 256 * seed + ny;
+  seed = 256 * seed + nv;
+  seed = 256 * seed + nw;
+  seed = 256 * seed + nu;
   mtgen.seed(seed);
 }
 
@@ -44,37 +43,34 @@ int
 IntGenerator::get()
 {
   double d = dis(mtgen);
-  auto num_inter = static_cast<int>(static_cast<double>(2*maxim)/(1.0-probab));
-  int num_zero_inter = num_inter - 2*maxim;
-  if (d < static_cast<double>(num_zero_inter)/num_inter)
+  auto num_inter = static_cast<int>(static_cast<double>(2 * maxim) / (1.0 - probab));
+  int num_zero_inter = num_inter - 2 * maxim;
+  if (d < static_cast<double>(num_zero_inter) / num_inter)
     return 0;
-  return static_cast<int>((d*num_inter)-num_zero_inter-maxim);
+  return static_cast<int>((d * num_inter) - num_zero_inter - maxim);
 }
 
-Monom::Monom(int len)
-  : IntSequence(len)
+Monom::Monom(int len) : IntSequence(len)
 {
   for (int i = 0; i < len; i++)
     operator[](i) = intgen.get();
 }
 
-Monom::Monom(int len, int item)
-  : IntSequence(len, item)
+Monom::Monom(int len, int item) : IntSequence(len, item)
 {
 }
 
 double
-Monom::deriv(const IntSequence &vars) const
+Monom::deriv(const IntSequence& vars) const
 {
   double res = 1.0;
   int first_same_i = 0;
   for (int i = 0; i < vars.size(); i++)
     {
-      TL_RAISE_IF(vars[i] < 0 || vars[i] >= size(),
-                  "Wrong variable index in Monom::deriv");
+      TL_RAISE_IF(vars[i] < 0 || vars[i] >= size(), "Wrong variable index in Monom::deriv");
       if (vars[i] != vars[first_same_i])
         first_same_i = i;
-      int mult = operator[](vars[i]) - (i-first_same_i);
+      int mult = operator[](vars[i]) - (i - first_same_i);
       if (mult == 0)
         return 0;
       res *= mult;
@@ -83,14 +79,13 @@ Monom::deriv(const IntSequence &vars) const
 }
 
 void
-Monom::multiplyWith(int ex, const Monom &m)
+Monom::multiplyWith(int ex, const Monom& m)
 {
-  TL_RAISE_IF(size() != m.size(),
-              "Wrong sizes of monoms in Monom::multiplyWith");
+  TL_RAISE_IF(size() != m.size(), "Wrong sizes of monoms in Monom::multiplyWith");
   if (ex == 0)
     return;
   for (int i = 0; i < size(); i++)
-    operator[](i) += m[i]*ex;
+    operator[](i) += m[i] * ex;
 }
 
 void
@@ -102,18 +97,16 @@ Monom::print() const
   std::cout << ']';
 }
 
-Monom1Vector::Monom1Vector(int nxx, int l)
-  : nx(nxx), len(l)
+Monom1Vector::Monom1Vector(int nxx, int l) : nx(nxx), len(l)
 {
   for (int i = 0; i < len; i++)
     x.emplace_back(nx);
 }
 
 void
-Monom1Vector::deriv(const IntSequence &c, Vector &out) const
+Monom1Vector::deriv(const IntSequence& c, Vector& out) const
 {
-  TL_RAISE_IF(out.length() != len,
-              "Wrong length of output vector in Monom1Vector::deriv");
+  TL_RAISE_IF(out.length() != len, "Wrong length of output vector in Monom1Vector::deriv");
 
   for (int i = 0; i < len; i++)
     out[i] = x[i].deriv(c);
@@ -122,11 +115,10 @@ Monom1Vector::deriv(const IntSequence &c, Vector &out) const
 std::unique_ptr<FGSTensor>
 Monom1Vector::deriv(int dim) const
 {
-  auto res = std::make_unique<FGSTensor>(len, TensorDimens(Symmetry{dim},
-                                                           IntSequence{nx}));
+  auto res = std::make_unique<FGSTensor>(len, TensorDimens(Symmetry {dim}, IntSequence {nx}));
   for (Tensor::index it = res->begin(); it != res->end(); ++it)
     {
-      Vector outcol{res->getCol(*it)};
+      Vector outcol {res->getCol(*it)};
       deriv(it.getCoor(), outcol);
     }
   return res;
@@ -145,8 +137,7 @@ Monom1Vector::print() const
     }
 }
 
-Monom2Vector::Monom2Vector(int nyy, int nuu, int l)
-  : ny(nyy), nu(nuu), len(l)
+Monom2Vector::Monom2Vector(int nyy, int nuu, int l) : ny(nyy), nu(nuu), len(l)
 {
   for (int i = 0; i < len; i++)
     {
@@ -155,11 +146,10 @@ Monom2Vector::Monom2Vector(int nyy, int nuu, int l)
     }
 }
 
-Monom2Vector::Monom2Vector(const Monom1Vector &g, const Monom2Vector &xmon)
-  : ny(xmon.ny), nu(xmon.nu), len(g.len)
+Monom2Vector::Monom2Vector(const Monom1Vector& g, const Monom2Vector& xmon) :
+    ny(xmon.ny), nu(xmon.nu), len(g.len)
 {
-  TL_RAISE_IF(xmon.len != g.nx,
-              "Wrong number of x's in Monom2Vector constructor");
+  TL_RAISE_IF(xmon.len != g.nx, "Wrong number of x's in Monom2Vector constructor");
 
   for (int i = 0; i < len; i++)
     {
@@ -178,13 +168,10 @@ Monom2Vector::Monom2Vector(const Monom1Vector &g, const Monom2Vector &xmon)
 }
 
 void
-Monom2Vector::deriv(const Symmetry &s, const IntSequence &c,
-                    Vector &out) const
+Monom2Vector::deriv(const Symmetry& s, const IntSequence& c, Vector& out) const
 {
-  TL_RAISE_IF(out.length() != len,
-              "Wrong length of output vector in Monom2Vector::deriv");
-  TL_RAISE_IF(s.num() != 2,
-              "Wrong symmetry for Monom2Vector::deriv");
+  TL_RAISE_IF(out.length() != len, "Wrong length of output vector in Monom2Vector::deriv");
+  TL_RAISE_IF(s.num() != 2, "Wrong symmetry for Monom2Vector::deriv");
   TL_RAISE_IF(s.dimen() != c.size(),
               "Incompatible symmetry and coordinates in Monom2Vector::deriv");
   IntSequence cy(c, 0, s[0]);
@@ -194,13 +181,13 @@ Monom2Vector::deriv(const Symmetry &s, const IntSequence &c,
 }
 
 std::unique_ptr<FGSTensor>
-Monom2Vector::deriv(const Symmetry &s) const
+Monom2Vector::deriv(const Symmetry& s) const
 {
-  IntSequence nvs{ny, nu};
+  IntSequence nvs {ny, nu};
   auto t = std::make_unique<FGSTensor>(len, TensorDimens(s, nvs));
   for (Tensor::index it = t->begin(); it != t->end(); ++it)
     {
-      Vector col{t->getCol(*it)};
+      Vector col {t->getCol(*it)};
       deriv(s, it.getCoor(), col);
     }
   return t;
@@ -214,7 +201,7 @@ Monom2Vector::deriv(int maxdim) const
     for (int ydim = 0; ydim <= dim; ydim++)
       {
         int udim = dim - ydim;
-        res.insert(deriv(Symmetry{ydim, udim}));
+        res.insert(deriv(Symmetry {ydim, udim}));
       }
   return res;
 }
@@ -246,33 +233,30 @@ Monom4Vector::init_random()
     }
 }
 
-Monom4Vector::Monom4Vector(int l, int ny, int nu)
-  : len(l), nx1(ny), nx2(nu), nx3(0), nx4(1)
+Monom4Vector::Monom4Vector(int l, int ny, int nu) : len(l), nx1(ny), nx2(nu), nx3(0), nx4(1)
 {
   init_random();
 }
 
-Monom4Vector::Monom4Vector(int l, int ny, int nu, int nup)
-  : len(l), nx1(ny), nx2(nu), nx3(nup), nx4(1)
+Monom4Vector::Monom4Vector(int l, int ny, int nu, int nup) :
+    len(l), nx1(ny), nx2(nu), nx3(nup), nx4(1)
 {
   init_random();
 }
 
-Monom4Vector::Monom4Vector(int l, int nbigg, int ng, int ny, int nu)
-  : len(l), nx1(nbigg), nx2(ng), nx3(ny), nx4(nu)
+Monom4Vector::Monom4Vector(int l, int nbigg, int ng, int ny, int nu) :
+    len(l), nx1(nbigg), nx2(ng), nx3(ny), nx4(nu)
 {
   init_random();
 }
 
-Monom4Vector::Monom4Vector(const Monom4Vector &f, const Monom4Vector &bigg,
-                           const Monom4Vector &g)
-  : len(f.len), nx1(bigg.nx1), nx2(bigg.nx2), nx3(bigg.nx3), nx4(1)
+Monom4Vector::Monom4Vector(const Monom4Vector& f, const Monom4Vector& bigg, const Monom4Vector& g) :
+    len(f.len), nx1(bigg.nx1), nx2(bigg.nx2), nx3(bigg.nx3), nx4(1)
 {
-  TL_RAISE_IF(!(bigg.nx1 == g.nx1 && bigg.nx2 == g.nx2 && g.nx3 == 0
-                && bigg.nx4 == 1 && g.nx4 == 1),
-              "Incompatible g with G");
-  TL_RAISE_IF(!(bigg.len == f.nx1 && g.len == f.nx2
-                && bigg.nx1 == f.nx3 && bigg.nx2 == f.nx4),
+  TL_RAISE_IF(
+      !(bigg.nx1 == g.nx1 && bigg.nx2 == g.nx2 && g.nx3 == 0 && bigg.nx4 == 1 && g.nx4 == 1),
+      "Incompatible g with G");
+  TL_RAISE_IF(!(bigg.len == f.nx1 && g.len == f.nx2 && bigg.nx1 == f.nx3 && bigg.nx2 == f.nx4),
               "Incompatible g or G with f");
 
   for (int i = 0; i < len; i++)
@@ -310,13 +294,10 @@ Monom4Vector::Monom4Vector(const Monom4Vector &f, const Monom4Vector &bigg,
 }
 
 void
-Monom4Vector::deriv(const Symmetry &s, const IntSequence &coor,
-                    Vector &out) const
+Monom4Vector::deriv(const Symmetry& s, const IntSequence& coor, Vector& out) const
 {
-  TL_RAISE_IF(out.length() != len,
-              "Wrong length of output vector in Monom4Vector::deriv");
-  TL_RAISE_IF(s.num() != 4,
-              "Wrong symmetry for Monom4Vector::deriv");
+  TL_RAISE_IF(out.length() != len, "Wrong length of output vector in Monom4Vector::deriv");
+  TL_RAISE_IF(s.num() != 4, "Wrong symmetry for Monom4Vector::deriv");
   TL_RAISE_IF(s.dimen() != coor.size(),
               "Incompatible symmetry and coordinates in Monom4Vector::deriv");
 
@@ -324,24 +305,24 @@ Monom4Vector::deriv(const Symmetry &s, const IntSequence &coor,
     {
       out[i] = 1;
       int off = 0;
-      out[i] *= x1[i].deriv(IntSequence(coor, off, off+s[0]));
+      out[i] *= x1[i].deriv(IntSequence(coor, off, off + s[0]));
       off += s[0];
-      out[i] *= x2[i].deriv(IntSequence(coor, off, off+s[1]));
+      out[i] *= x2[i].deriv(IntSequence(coor, off, off + s[1]));
       off += s[1];
-      out[i] *= x3[i].deriv(IntSequence(coor, off, off+s[2]));
+      out[i] *= x3[i].deriv(IntSequence(coor, off, off + s[2]));
       off += s[2];
-      out[i] *= x4[i].deriv(IntSequence(coor, off, off+s[3]));
+      out[i] *= x4[i].deriv(IntSequence(coor, off, off + s[3]));
     }
 }
 
 std::unique_ptr<FGSTensor>
-Monom4Vector::deriv(const Symmetry &s) const
+Monom4Vector::deriv(const Symmetry& s) const
 {
-  IntSequence nvs{nx1, nx2, nx3, nx4};
+  IntSequence nvs {nx1, nx2, nx3, nx4};
   auto res = std::make_unique<FGSTensor>(len, TensorDimens(s, nvs));
   for (Tensor::index run = res->begin(); run != res->end(); ++run)
     {
-      Vector col{res->getCol(*run)};
+      Vector col {res->getCol(*run)};
       deriv(s, run.getCoor(), col);
     }
   return res;
@@ -350,14 +331,14 @@ Monom4Vector::deriv(const Symmetry &s) const
 FSSparseTensor
 Monom4Vector::deriv(int dim) const
 {
-  IntSequence cum{0, nx1, nx1+nx2, nx1+nx2+nx3};
+  IntSequence cum {0, nx1, nx1 + nx2, nx1 + nx2 + nx3};
 
-  FSSparseTensor res(dim, nx1+nx2+nx3+nx4, len);
+  FSSparseTensor res(dim, nx1 + nx2 + nx3 + nx4, len);
 
-  FFSTensor dummy(0, nx1+nx2+nx3+nx4, dim);
+  FFSTensor dummy(0, nx1 + nx2 + nx3 + nx4, dim);
   for (Tensor::index run = dummy.begin(); run != dummy.end(); ++run)
     {
-      Symmetry ind_sym{0, 0, 0, 0};
+      Symmetry ind_sym {0, 0, 0, 0};
       IntSequence ind(run.getCoor());
       for (int i = 0; i < ind.size(); i++)
         {
@@ -381,8 +362,8 @@ Monom4Vector::deriv(int dim) const
 void
 Monom4Vector::print() const
 {
-  std::cout << "Variables: x1(" << nx1 << ") x2(" << nx2
-            << ") x3(" << nx3 << ") x4(" << nx4 << ")\n"
+  std::cout << "Variables: x1(" << nx1 << ") x2(" << nx2 << ") x3(" << nx3 << ") x4(" << nx4
+            << ")\n"
             << "Rows: " << len << '\n';
   for (int i = 0; i < len; i++)
     {
@@ -399,8 +380,9 @@ Monom4Vector::print() const
 }
 
 SparseDerivGenerator::SparseDerivGenerator(int nf, int ny, int nu, int nup, int nbigg, int ng,
-                                           int mx, double prob, int maxdim)
-  : maxdimen(maxdim), bigg(4), g(4), rcont(4)
+                                           int mx, double prob, int maxdim) :
+    maxdimen(maxdim),
+    bigg(4), g(4), rcont(4)
 {
   intgen.init(nf, ny, nu, nup, nbigg, mx, prob);
 
@@ -411,7 +393,7 @@ SparseDerivGenerator::SparseDerivGenerator(int nf, int ny, int nu, int nup, int
 
   for (int dim = 1; dim <= maxdimen; dim++)
     {
-      for (auto &si : SymmetrySet(dim, 4))
+      for (auto& si : SymmetrySet(dim, 4))
         {
           bigg.insert(bigg_m.deriv(si));
           rcont.insert(r.deriv(si));
@@ -423,9 +405,10 @@ SparseDerivGenerator::SparseDerivGenerator(int nf, int ny, int nu, int nup, int
     }
 }
 
-DenseDerivGenerator::DenseDerivGenerator(int ng, int nx, int ny, int nu,
-                                         int mx, double prob, int maxdim)
-  : maxdimen(maxdim), xcont(0), rcont(0), ts(maxdimen), uxcont(0), uts(maxdimen)
+DenseDerivGenerator::DenseDerivGenerator(int ng, int nx, int ny, int nu, int mx, double prob,
+                                         int maxdim) :
+    maxdimen(maxdim),
+    xcont(0), rcont(0), ts(maxdimen), uxcont(0), uts(maxdimen)
 {
   intgen.init(ng, nx, ny, nu, nu, mx, prob);
   Monom1Vector g(nx, ng);
@@ -434,7 +417,7 @@ DenseDerivGenerator::DenseDerivGenerator(int ng, int nx, int ny, int nu,
   xcont = x.deriv(maxdimen);
   rcont = r.deriv(maxdimen);
   for (int d = 1; d <= maxdimen; d++)
-    ts[d-1] = g.deriv(d);
+    ts[d - 1] = g.deriv(d);
 }
 
 void
diff --git a/mex/sources/libkorder/tl/tests/monoms.hh b/mex/sources/libkorder/tl/tests/monoms.hh
index 23bd2ef85b06318dcb562d3d93a6ce8e92ec7194..7a6295c4ee804ccfd90533425cb574783467237d 100644
--- a/mex/sources/libkorder/tl/tests/monoms.hh
+++ b/mex/sources/libkorder/tl/tests/monoms.hh
@@ -21,22 +21,23 @@
 #ifndef MONOMS_H
 #define MONOMS_H
 
-#include <vector>
-#include <random>
 #include <memory>
+#include <random>
+#include <vector>
 
-#include "int_sequence.hh"
+#include "Vector.hh"
 #include "gs_tensor.hh"
-#include "t_container.hh"
+#include "int_sequence.hh"
 #include "sparse_tensor.hh"
-#include "Vector.hh"
+#include "t_container.hh"
 
 class IntGenerator
 {
-  int maxim{5};
-  double probab{0.3};
+  int maxim {5};
+  double probab {0.3};
   std::mt19937 mtgen;
   std::uniform_real_distribution<> dis;
+
 public:
   IntGenerator() = default;
   void init(int nf, int ny, int nv, int nw, int nu, int mx, double prob);
@@ -48,11 +49,11 @@ extern IntGenerator intgen;
 class Monom : public IntSequence
 {
 public:
-  Monom(int len); // generate a random monom
+  Monom(int len);           // generate a random monom
   Monom(int len, int item); // generate monom whose items are the given item
-  double deriv(const IntSequence &vars) const;
+  double deriv(const IntSequence& vars) const;
   // this = this·mᵉˣ (in monomial sense)
-  void multiplyWith(int ex, const Monom &m);
+  void multiplyWith(int ex, const Monom& m);
   void print() const;
 };
 
@@ -63,10 +64,11 @@ class Monom1Vector
   int nx;
   int len;
   std::vector<Monom> x;
+
 public:
   Monom1Vector(int nxx, int l);
   ~Monom1Vector() = default;
-  void deriv(const IntSequence &c, Vector &out) const;
+  void deriv(const IntSequence& c, Vector& out) const;
   std::unique_ptr<FGSTensor> deriv(int dim) const;
   void print() const;
 };
@@ -76,14 +78,15 @@ class Monom2Vector
   int ny, nu;
   int len;
   std::vector<Monom> y, u;
+
 public:
   // Generate random vector of monom two vector
   Monom2Vector(int nyy, int nuu, int l);
   // Calculate g(x(y,u))
-  Monom2Vector(const Monom1Vector &g, const Monom2Vector &xmon);
+  Monom2Vector(const Monom1Vector& g, const Monom2Vector& xmon);
   ~Monom2Vector() = default;
-  void deriv(const Symmetry &s, const IntSequence &c, Vector &out) const;
-  std::unique_ptr<FGSTensor> deriv(const Symmetry &s) const;
+  void deriv(const Symmetry& s, const IntSequence& c, Vector& out) const;
+  std::unique_ptr<FGSTensor> deriv(const Symmetry& s) const;
   FGSContainer deriv(int maxdim) const;
   void print() const;
 };
@@ -93,6 +96,7 @@ class Monom4Vector
   int len;
   int nx1, nx2, nx3, nx4;
   std::vector<Monom> x1, x2, x3, x4;
+
 public:
   /* Random for g(y,u,σ) */
   Monom4Vector(int l, int ny, int nu);
@@ -101,13 +105,13 @@ public:
   /* Random for f(y⁺,y,y⁻,u) */
   Monom4Vector(int l, int nbigg, int ng, int ny, int nu);
   /* Substitution f(G(y,u,u′,σ),g(y,u,σ),y,u) */
-  Monom4Vector(const Monom4Vector &f, const Monom4Vector &bigg,
-               const Monom4Vector &g);
+  Monom4Vector(const Monom4Vector& f, const Monom4Vector& bigg, const Monom4Vector& g);
   ~Monom4Vector() = default;
   FSSparseTensor deriv(int dim) const;
-  std::unique_ptr<FGSTensor> deriv(const Symmetry &s) const;
-  void deriv(const Symmetry &s, const IntSequence &coor, Vector &out) const;
+  std::unique_ptr<FGSTensor> deriv(const Symmetry& s) const;
+  void deriv(const Symmetry& s, const IntSequence& coor, Vector& out) const;
   void print() const;
+
 protected:
   void init_random();
 };
@@ -119,8 +123,8 @@ struct SparseDerivGenerator
   FGSContainer g;
   FGSContainer rcont;
   std::vector<FSSparseTensor> ts;
-  SparseDerivGenerator(int nf, int ny, int nu, int nup, int nbigg, int ng,
-                       int mx, double prob, int maxdim);
+  SparseDerivGenerator(int nf, int ny, int nu, int nup, int nbigg, int ng, int mx, double prob,
+                       int maxdim);
 };
 
 struct DenseDerivGenerator
@@ -131,8 +135,7 @@ struct DenseDerivGenerator
   std::vector<std::unique_ptr<FGSTensor>> ts;
   UGSContainer uxcont;
   std::vector<std::unique_ptr<UGSTensor>> uts;
-  DenseDerivGenerator(int ng, int nx, int ny, int nu,
-                      int mx, double prob, int maxdim);
+  DenseDerivGenerator(int ng, int nx, int ny, int nu, int mx, double prob, int maxdim);
   void unfold();
 };
 
diff --git a/mex/sources/libkorder/tl/tests/tests.cc b/mex/sources/libkorder/tl/tests/tests.cc
index 384c02d0d76be66556a0d271b2a47ef196ba0a65..b25d52befe2233b32fdc20db0d17886738cd387b 100644
--- a/mex/sources/libkorder/tl/tests/tests.cc
+++ b/mex/sources/libkorder/tl/tests/tests.cc
@@ -19,48 +19,48 @@
  */
 
 #include "SylvException.hh"
-#include "tl_exception.hh"
-#include "gs_tensor.hh"
 #include "factory.hh"
+#include "gs_tensor.hh"
 #include "monoms.hh"
-#include "t_container.hh"
+#include "ps_tensor.hh"
+#include "rfs_tensor.hh"
 #include "stack_container.hh"
+#include "t_container.hh"
 #include "t_polynomial.hh"
-#include "rfs_tensor.hh"
-#include "ps_tensor.hh"
+#include "tl_exception.hh"
 #include "tl_static.hh"
 
+#include <cstdlib>
+#include <ctime>
+#include <iomanip>
+#include <iostream>
+#include <memory>
 #include <string>
 #include <utility>
-#include <memory>
 #include <vector>
-#include <ctime>
-#include <cstdlib>
-#include <iostream>
-#include <iomanip>
 
 class TestRunnable
 {
 public:
   const std::string name;
-  int dim; // dimension of the solved problem
+  int dim;  // dimension of the solved problem
   int nvar; // number of variable of the solved problem
-  TestRunnable(std::string name_arg, int d, int nv)
-    : name{std::move(name_arg)}, dim(d), nvar(nv)
+  TestRunnable(std::string name_arg, int d, int nv) : name {std::move(name_arg)}, dim(d), nvar(nv)
   {
   }
   virtual ~TestRunnable() = default;
   bool test() const;
   virtual bool run() const = 0;
+
 protected:
   template<class _Ttype>
-  static bool index_forward(const Symmetry &s, const IntSequence &nvs);
+  static bool index_forward(const Symmetry& s, const IntSequence& nvs);
 
   template<class _Ttype>
-  static bool index_backward(const Symmetry &s, const IntSequence &nvs);
+  static bool index_backward(const Symmetry& s, const IntSequence& nvs);
 
   template<class _Ttype>
-  static bool index_offset(const Symmetry &s, const IntSequence &nvs);
+  static bool index_offset(const Symmetry& s, const IntSequence& nvs);
 
   static bool fold_unfold(std::unique_ptr<FTensor> folded);
   static bool
@@ -76,31 +76,28 @@ protected:
     return fold_unfold(f.make<FRTensor>(r, nv, dim));
   }
   static bool
-  gs_fold_unfold(int r, const Symmetry &s, const IntSequence &nvs)
+  gs_fold_unfold(int r, const Symmetry& s, const IntSequence& nvs)
   {
     Factory f;
     return fold_unfold(f.make<FGSTensor>(r, s, nvs));
   }
 
-  static bool dense_prod(const Symmetry &bsym, const IntSequence &bnvs,
-                         int hdim, int hnv, int rows);
+  static bool dense_prod(const Symmetry& bsym, const IntSequence& bnvs, int hdim, int hnv,
+                         int rows);
 
   static bool folded_monomial(int ng, int nx, int ny, int nu, int dim);
 
   static bool unfolded_monomial(int ng, int nx, int ny, int nu, int dim);
 
-  static bool fold_zcont(int nf, int ny, int nu, int nup, int nbigg,
-                         int ng, int dim);
+  static bool fold_zcont(int nf, int ny, int nu, int nup, int nbigg, int ng, int dim);
 
-  static bool unfold_zcont(int nf, int ny, int nu, int nup, int nbigg,
-                           int ng, int dim);
+  static bool unfold_zcont(int nf, int ny, int nu, int nup, int nbigg, int ng, int dim);
 
   static bool folded_contraction(int r, int nv, int dim);
 
   static bool unfolded_contraction(int r, int nv, int dim);
 
   static bool poly_eval(int r, int nv, int maxdim);
-
 };
 
 bool
@@ -110,7 +107,7 @@ TestRunnable::test() const
   clock_t start = clock();
   bool passed = run();
   clock_t end = clock();
-  std::cout << "CPU time " << static_cast<double>(end-start)/CLOCKS_PER_SEC
+  std::cout << "CPU time " << static_cast<double>(end - start) / CLOCKS_PER_SEC
             << " (CPU seconds)..................";
   if (passed)
     std::cout << "passed\n\n";
@@ -124,7 +121,7 @@ TestRunnable::test() const
 /****************************************************/
 template<class _Ttype>
 bool
-TestRunnable::index_forward(const Symmetry &s, const IntSequence &nvs)
+TestRunnable::index_forward(const Symmetry& s, const IntSequence& nvs)
 {
   int fails = 0;
   int ndecr = 0;
@@ -156,7 +153,7 @@ TestRunnable::index_forward(const Symmetry &s, const IntSequence &nvs)
 
 template<class _Ttype>
 bool
-TestRunnable::index_backward(const Symmetry &s, const IntSequence &nvs)
+TestRunnable::index_backward(const Symmetry& s, const IntSequence& nvs)
 {
   int fails = 0;
   int ndecr = 0;
@@ -187,7 +184,7 @@ TestRunnable::index_backward(const Symmetry &s, const IntSequence &nvs)
 
 template<class _Ttype>
 bool
-TestRunnable::index_offset(const Symmetry &s, const IntSequence &nvs)
+TestRunnable::index_offset(const Symmetry& s, const IntSequence& nvs)
 {
   int fails = 0;
   int nincr = 0;
@@ -223,12 +220,11 @@ TestRunnable::fold_unfold(std::unique_ptr<FTensor> folded)
 }
 
 bool
-TestRunnable::dense_prod(const Symmetry &bsym, const IntSequence &bnvs,
-                         int hdim, int hnv, int rows)
+TestRunnable::dense_prod(const Symmetry& bsym, const IntSequence& bnvs, int hdim, int hnv, int rows)
 {
   Factory f;
-  FGSContainer cont{f.makeCont<FGSTensor, FGSContainer>(hnv, bnvs, bsym.dimen()-hdim+1)};
-  auto fh = f.make<FGSTensor>(rows, Symmetry{hdim}, IntSequence(1, hnv));
+  FGSContainer cont {f.makeCont<FGSTensor, FGSContainer>(hnv, bnvs, bsym.dimen() - hdim + 1)};
+  auto fh = f.make<FGSTensor>(rows, Symmetry {hdim}, IntSequence(1, hnv));
   UGSTensor uh(*fh);
   FGSTensor fb(rows, TensorDimens(bsym, bnvs));
   fb.getData().zeros();
@@ -249,9 +245,12 @@ TestRunnable::dense_prod(const Symmetry &bsym, const IntSequence &bnvs,
   double norm1 = btmp.getNorm1();
   double normInf = btmp.getNormInf();
 
-  std::cout << "\ttime for folded product:     " << static_cast<double>(s2-s1)/CLOCKS_PER_SEC << '\n'
-            << "\ttime for unfolded product:   " << static_cast<double>(s5-s4)/CLOCKS_PER_SEC << '\n'
-            << "\ttime for container convert:  " << static_cast<double>(s3-s2)/CLOCKS_PER_SEC << '\n'
+  std::cout << "\ttime for folded product:     " << static_cast<double>(s2 - s1) / CLOCKS_PER_SEC
+            << '\n'
+            << "\ttime for unfolded product:   " << static_cast<double>(s5 - s4) / CLOCKS_PER_SEC
+            << '\n'
+            << "\ttime for container convert:  " << static_cast<double>(s3 - s2) / CLOCKS_PER_SEC
+            << '\n'
             << "\tunfolded difference normMax: " << norm << '\n'
             << "\tunfolded difference norm1:   " << norm1 << '\n'
             << "\tunfolded difference normInf: " << normInf << '\n';
@@ -264,25 +263,24 @@ TestRunnable::folded_monomial(int ng, int nx, int ny, int nu, int dim)
 {
   clock_t gen_time = clock();
   DenseDerivGenerator gen(ng, nx, ny, nu, 5, 0.3, dim);
-  gen_time = clock()-gen_time;
-  std::cout << "\ttime for monom generation: "
-            << static_cast<double>(gen_time)/CLOCKS_PER_SEC << '\n';
-  IntSequence nvs{ny, nu};
+  gen_time = clock() - gen_time;
+  std::cout << "\ttime for monom generation: " << static_cast<double>(gen_time) / CLOCKS_PER_SEC
+            << '\n';
+  IntSequence nvs {ny, nu};
   double maxnorm = 0;
   for (int ydim = 0; ydim <= dim; ydim++)
     {
-      Symmetry s{ydim, dim-ydim};
+      Symmetry s {ydim, dim - ydim};
       std::cout << "\tSymmetry: ";
       s.print();
       FGSTensor res(ng, TensorDimens(s, nvs));
       res.getData().zeros();
       clock_t stime = clock();
       for (int d = 1; d <= dim; d++)
-        gen.xcont.multAndAdd(*(gen.ts[d-1]), res);
+        gen.xcont.multAndAdd(*(gen.ts[d - 1]), res);
       stime = clock() - stime;
-      std::cout << "\t\ttime for symmetry: "
-                << static_cast<double>(stime)/CLOCKS_PER_SEC << '\n';
-      const FGSTensor &mres = gen.rcont.get(s);
+      std::cout << "\t\ttime for symmetry: " << static_cast<double>(stime) / CLOCKS_PER_SEC << '\n';
+      const FGSTensor& mres = gen.rcont.get(s);
       res.add(-1.0, mres);
       double normtmp = res.getData().getMax();
       std::cout << "\t\terror normMax:     " << normtmp << '\n';
@@ -296,30 +294,29 @@ TestRunnable::unfolded_monomial(int ng, int nx, int ny, int nu, int dim)
 {
   clock_t gen_time = clock();
   DenseDerivGenerator gen(ng, nx, ny, nu, 5, 0.3, dim);
-  gen_time = clock()-gen_time;
-  std::cout << "\ttime for monom generation: "
-            << static_cast<double>(gen_time)/CLOCKS_PER_SEC << '\n';
+  gen_time = clock() - gen_time;
+  std::cout << "\ttime for monom generation: " << static_cast<double>(gen_time) / CLOCKS_PER_SEC
+            << '\n';
   clock_t u_time = clock();
   gen.unfold();
   u_time = clock() - u_time;
-  std::cout << "\ttime for monom unfolding:  "
-            << static_cast<double>(u_time)/CLOCKS_PER_SEC << '\n';
-  IntSequence nvs{ny, nu};
+  std::cout << "\ttime for monom unfolding:  " << static_cast<double>(u_time) / CLOCKS_PER_SEC
+            << '\n';
+  IntSequence nvs {ny, nu};
   double maxnorm = 0;
   for (int ydim = 0; ydim <= dim; ydim++)
     {
-      Symmetry s{ydim, dim-ydim};
+      Symmetry s {ydim, dim - ydim};
       std::cout << "\tSymmetry: ";
       s.print();
       UGSTensor res(ng, TensorDimens(s, nvs));
       res.getData().zeros();
       clock_t stime = clock();
       for (int d = 1; d <= dim; d++)
-        gen.uxcont.multAndAdd(*(gen.uts[d-1]), res);
+        gen.uxcont.multAndAdd(*(gen.uts[d - 1]), res);
       stime = clock() - stime;
-      std::cout << "\t\ttime for symmetry: "
-                << static_cast<double>(stime)/CLOCKS_PER_SEC << '\n';
-      const FGSTensor &mres = gen.rcont.get(s);
+      std::cout << "\t\ttime for symmetry: " << static_cast<double>(stime) / CLOCKS_PER_SEC << '\n';
+      const FGSTensor& mres = gen.rcont.get(s);
       FGSTensor foldres(res);
       foldres.add(-1.0, mres);
       double normtmp = foldres.getData().getMax();
@@ -330,29 +327,26 @@ TestRunnable::unfolded_monomial(int ng, int nx, int ny, int nu, int dim)
 }
 
 bool
-TestRunnable::fold_zcont(int nf, int ny, int nu, int nup, int nbigg,
-                         int ng, int dim)
+TestRunnable::fold_zcont(int nf, int ny, int nu, int nup, int nbigg, int ng, int dim)
 {
   clock_t gen_time = clock();
-  SparseDerivGenerator dg(nf, ny, nu, nup, nbigg, ng,
-                          5, 0.55, dim);
-  gen_time = clock()-gen_time;
+  SparseDerivGenerator dg(nf, ny, nu, nup, nbigg, ng, 5, 0.55, dim);
+  gen_time = clock() - gen_time;
   for (int d = 1; d <= dim; d++)
-    std::cout << "\tfill of dim=" << d << " tensor:     "
-              << std::setprecision(2) << std::fixed << std::setw(6)
-              << 100*dg.ts[d-1].getFillFactor()
-              << std::setprecision(6) << std::defaultfloat << " %\n";
-  std::cout << "\ttime for monom generation: "
-            << static_cast<double>(gen_time)/CLOCKS_PER_SEC << '\n';
-
-  IntSequence nvs{ny, nu, nup, 1};
+    std::cout << "\tfill of dim=" << d << " tensor:     " << std::setprecision(2) << std::fixed
+              << std::setw(6) << 100 * dg.ts[d - 1].getFillFactor() << std::setprecision(6)
+              << std::defaultfloat << " %\n";
+  std::cout << "\ttime for monom generation: " << static_cast<double>(gen_time) / CLOCKS_PER_SEC
+            << '\n';
+
+  IntSequence nvs {ny, nu, nup, 1};
   double maxnorm = 0.0;
 
   // form ZContainer
   FoldedZContainer zc(&dg.bigg, nbigg, &dg.g, ng, ny, nu);
 
   for (int d = 2; d <= dim; d++)
-    for (auto &si : SymmetrySet(d, 4))
+    for (auto& si : SymmetrySet(d, 4))
       {
         std::cout << "\tSymmetry: ";
         si.print();
@@ -360,11 +354,11 @@ TestRunnable::fold_zcont(int nf, int ny, int nu, int nup, int nbigg,
         res.getData().zeros();
         clock_t stime = clock();
         for (int l = 1; l <= si.dimen(); l++)
-          zc.multAndAdd(dg.ts[l-1], res);
+          zc.multAndAdd(dg.ts[l - 1], res);
         stime = clock() - stime;
-        std::cout << "\t\ttime for symmetry: "
-                  << static_cast<double>(stime)/CLOCKS_PER_SEC << '\n';
-        const FGSTensor &mres = dg.rcont.get(si);
+        std::cout << "\t\ttime for symmetry: " << static_cast<double>(stime) / CLOCKS_PER_SEC
+                  << '\n';
+        const FGSTensor& mres = dg.rcont.get(si);
         res.add(-1.0, mres);
         double normtmp = res.getData().getMax();
         std::cout << "\t\terror normMax:     " << normtmp << '\n';
@@ -375,36 +369,33 @@ TestRunnable::fold_zcont(int nf, int ny, int nu, int nup, int nbigg,
 }
 
 bool
-TestRunnable::unfold_zcont(int nf, int ny, int nu, int nup, int nbigg,
-                           int ng, int dim)
+TestRunnable::unfold_zcont(int nf, int ny, int nu, int nup, int nbigg, int ng, int dim)
 {
   clock_t gen_time = clock();
-  SparseDerivGenerator dg(nf, ny, nu, nup, nbigg, ng,
-                          5, 0.55, dim);
-  gen_time = clock()-gen_time;
+  SparseDerivGenerator dg(nf, ny, nu, nup, nbigg, ng, 5, 0.55, dim);
+  gen_time = clock() - gen_time;
   for (int d = 1; d <= dim; d++)
-    std::cout << "\tfill of dim=" << d << " tensor:     "
-              << std::setprecision(2) << std::fixed << std::setw(6)
-              << 100*dg.ts[d-1].getFillFactor()
-              << std::setprecision(6) << std::defaultfloat << " %\n";
-  std::cout << "\ttime for monom generation: "
-            << static_cast<double>(gen_time)/CLOCKS_PER_SEC << '\n';
+    std::cout << "\tfill of dim=" << d << " tensor:     " << std::setprecision(2) << std::fixed
+              << std::setw(6) << 100 * dg.ts[d - 1].getFillFactor() << std::setprecision(6)
+              << std::defaultfloat << " %\n";
+  std::cout << "\ttime for monom generation: " << static_cast<double>(gen_time) / CLOCKS_PER_SEC
+            << '\n';
 
   clock_t con_time = clock();
   UGSContainer uG_cont(dg.bigg);
   UGSContainer ug_cont(dg.g);
-  con_time = clock()-con_time;
-  std::cout << "\ttime for container unfold: "
-            << static_cast<double>(con_time)/CLOCKS_PER_SEC << '\n';
+  con_time = clock() - con_time;
+  std::cout << "\ttime for container unfold: " << static_cast<double>(con_time) / CLOCKS_PER_SEC
+            << '\n';
 
-  IntSequence nvs{ny, nu, nup, 1};
+  IntSequence nvs {ny, nu, nup, 1};
   double maxnorm = 0.0;
 
   // Form ZContainer
   UnfoldedZContainer zc(&uG_cont, nbigg, &ug_cont, ng, ny, nu);
 
   for (int d = 2; d <= dim; d++)
-    for (auto &si : SymmetrySet(d, 4))
+    for (auto& si : SymmetrySet(d, 4))
       {
         std::cout << "\tSymmetry: ";
         si.print();
@@ -412,12 +403,12 @@ TestRunnable::unfold_zcont(int nf, int ny, int nu, int nup, int nbigg,
         res.getData().zeros();
         clock_t stime = clock();
         for (int l = 1; l <= si.dimen(); l++)
-          zc.multAndAdd(dg.ts[l-1], res);
+          zc.multAndAdd(dg.ts[l - 1], res);
         stime = clock() - stime;
-        std::cout << "\t\ttime for symmetry: "
-                  << static_cast<double>(stime)/CLOCKS_PER_SEC << '\n';
+        std::cout << "\t\ttime for symmetry: " << static_cast<double>(stime) / CLOCKS_PER_SEC
+                  << '\n';
         FGSTensor fold_res(res);
-        const FGSTensor &mres = dg.rcont.get(si);
+        const FGSTensor& mres = dg.rcont.get(si);
         fold_res.add(-1.0, mres);
         double normtmp = fold_res.getData().getMax();
         std::cout << "\t\terror normMax:     " << normtmp << '\n';
@@ -431,12 +422,12 @@ bool
 TestRunnable::folded_contraction(int r, int nv, int dim)
 {
   Factory fact;
-  Vector x{fact.makeVector(nv)};
+  Vector x {fact.makeVector(nv)};
 
   auto forig = fact.make<FFSTensor>(r, nv, dim);
   auto f = std::make_unique<FFSTensor>(*forig);
   clock_t ctime = clock();
-  for (int d = dim-1; d > 0; d--)
+  for (int d = dim - 1; d > 0; d--)
     f = std::make_unique<FFSTensor>(*f, ConstVector(x));
   ctime = clock() - ctime;
   Vector res(forig->nrows());
@@ -452,10 +443,10 @@ TestRunnable::folded_contraction(int r, int nv, int dim)
   utime = clock() - utime;
 
   v.add(-1.0, res);
-  std::cout << "\ttime for folded contraction: "
-            << static_cast<double>(ctime)/CLOCKS_PER_SEC << '\n'
-            << "\ttime for unfolded power:     "
-            << static_cast<double>(utime)/CLOCKS_PER_SEC << '\n'
+  std::cout << "\ttime for folded contraction: " << static_cast<double>(ctime) / CLOCKS_PER_SEC
+            << '\n'
+            << "\ttime for unfolded power:     " << static_cast<double>(utime) / CLOCKS_PER_SEC
+            << '\n'
             << "\terror normMax:     " << v.getMax() << '\n'
             << "\terror norm1:       " << v.getNorm1() << '\n';
 
@@ -466,13 +457,13 @@ bool
 TestRunnable::unfolded_contraction(int r, int nv, int dim)
 {
   Factory fact;
-  Vector x{fact.makeVector(nv)};
+  Vector x {fact.makeVector(nv)};
 
   auto forig = fact.make<FFSTensor>(r, nv, dim);
   UFSTensor uorig(*forig);
   auto u = std::make_unique<UFSTensor>(uorig);
   clock_t ctime = clock();
-  for (int d = dim-1; d > 0; d--)
+  for (int d = dim - 1; d > 0; d--)
     u = std::make_unique<UFSTensor>(*u, ConstVector(x));
   ctime = clock() - ctime;
   Vector res(uorig.nrows());
@@ -487,10 +478,10 @@ TestRunnable::unfolded_contraction(int r, int nv, int dim)
   utime = clock() - utime;
 
   v.add(-1.0, res);
-  std::cout << "\ttime for unfolded contraction: "
-            << static_cast<double>(ctime)/CLOCKS_PER_SEC << '\n'
-            << "\ttime for unfolded power:       "
-            << static_cast<double>(utime)/CLOCKS_PER_SEC << '\n'
+  std::cout << "\ttime for unfolded contraction: " << static_cast<double>(ctime) / CLOCKS_PER_SEC
+            << '\n'
+            << "\ttime for unfolded power:       " << static_cast<double>(utime) / CLOCKS_PER_SEC
+            << '\n'
             << "\terror normMax:     " << v.getMax() << '\n'
             << "\terror norm1:       " << v.getNorm1() << '\n';
 
@@ -501,7 +492,7 @@ bool
 TestRunnable::poly_eval(int r, int nv, int maxdim)
 {
   Factory fact;
-  Vector x{fact.makeVector(nv)};
+  Vector x {fact.makeVector(nv)};
 
   Vector out_ft(r);
   out_ft.zeros();
@@ -512,33 +503,33 @@ TestRunnable::poly_eval(int r, int nv, int maxdim)
   Vector out_uh(r);
   out_uh.zeros();
 
-  FTensorPolynomial fp{fact.makePoly<FFSTensor, FTensorPolynomial>(r, nv, maxdim)};
+  FTensorPolynomial fp {fact.makePoly<FFSTensor, FTensorPolynomial>(r, nv, maxdim)};
 
   clock_t ft_cl = clock();
   fp.evalTrad(out_ft, x);
   ft_cl = clock() - ft_cl;
-  std::cout << "\ttime for folded power eval:    "
-            << static_cast<double>(ft_cl)/CLOCKS_PER_SEC << '\n';
+  std::cout << "\ttime for folded power eval:    " << static_cast<double>(ft_cl) / CLOCKS_PER_SEC
+            << '\n';
 
   clock_t fh_cl = clock();
   fp.evalHorner(out_fh, x);
   fh_cl = clock() - fh_cl;
-  std::cout << "\ttime for folded horner eval:   "
-            << static_cast<double>(fh_cl)/CLOCKS_PER_SEC << '\n';
+  std::cout << "\ttime for folded horner eval:   " << static_cast<double>(fh_cl) / CLOCKS_PER_SEC
+            << '\n';
 
-  UTensorPolynomial up{fp};
+  UTensorPolynomial up {fp};
 
   clock_t ut_cl = clock();
   up.evalTrad(out_ut, x);
   ut_cl = clock() - ut_cl;
-  std::cout << "\ttime for unfolded power eval:  "
-            << static_cast<double>(ut_cl)/CLOCKS_PER_SEC << '\n';
+  std::cout << "\ttime for unfolded power eval:  " << static_cast<double>(ut_cl) / CLOCKS_PER_SEC
+            << '\n';
 
   clock_t uh_cl = clock();
   up.evalHorner(out_uh, x);
   uh_cl = clock() - uh_cl;
-  std::cout << "\ttime for unfolded horner eval: "
-            << static_cast<double>(uh_cl)/CLOCKS_PER_SEC << '\n';
+  std::cout << "\ttime for unfolded horner eval: " << static_cast<double>(uh_cl) / CLOCKS_PER_SEC
+            << '\n';
 
   out_ft.add(-1.0, out_ut);
   double max_ft = out_ft.getMax();
@@ -551,7 +542,7 @@ TestRunnable::poly_eval(int r, int nv, int maxdim)
             << "\tfolded horner error norm max:    " << max_fh << '\n'
             << "\tunfolded horner error norm max:  " << max_uh << '\n';
 
-  return (max_ft+max_fh+max_uh < 1.0e-10);
+  return (max_ft + max_fh + max_uh < 1.0e-10);
 }
 
 /****************************************************/
@@ -560,15 +551,14 @@ TestRunnable::poly_eval(int r, int nv, int maxdim)
 class SmallIndexForwardFold : public TestRunnable
 {
 public:
-  SmallIndexForwardFold()
-    : TestRunnable("small index forward for fold (44)(222)", 5, 4)
+  SmallIndexForwardFold() : TestRunnable("small index forward for fold (44)(222)", 5, 4)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{2, 3};
-    IntSequence nvs{4, 2};
+    Symmetry s {2, 3};
+    IntSequence nvs {4, 2};
     return index_forward<FGSTensor>(s, nvs);
   }
 };
@@ -576,15 +566,14 @@ public:
 class SmallIndexForwardUnfold : public TestRunnable
 {
 public:
-  SmallIndexForwardUnfold()
-    : TestRunnable("small index forward for unfold (44)(222)", 5, 4)
+  SmallIndexForwardUnfold() : TestRunnable("small index forward for unfold (44)(222)", 5, 4)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{2, 3};
-    IntSequence nvs{4, 2};
+    Symmetry s {2, 3};
+    IntSequence nvs {4, 2};
     return index_forward<UGSTensor>(s, nvs);
   }
 };
@@ -592,15 +581,14 @@ public:
 class IndexForwardFold : public TestRunnable
 {
 public:
-  IndexForwardFold()
-    : TestRunnable("index forward for fold (55)(222)(22)", 7, 5)
+  IndexForwardFold() : TestRunnable("index forward for fold (55)(222)(22)", 7, 5)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{2, 3, 2};
-    IntSequence nvs{5, 2, 2};
+    Symmetry s {2, 3, 2};
+    IntSequence nvs {5, 2, 2};
     return index_forward<FGSTensor>(s, nvs);
   }
 };
@@ -608,15 +596,14 @@ public:
 class IndexForwardUnfold : public TestRunnable
 {
 public:
-  IndexForwardUnfold()
-    : TestRunnable("index forward for unfold (55)(222)(22)", 7, 5)
+  IndexForwardUnfold() : TestRunnable("index forward for unfold (55)(222)(22)", 7, 5)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{2, 3, 2};
-    IntSequence nvs{5, 2, 2};
+    Symmetry s {2, 3, 2};
+    IntSequence nvs {5, 2, 2};
     return index_forward<UGSTensor>(s, nvs);
   }
 };
@@ -624,15 +611,14 @@ public:
 class SmallIndexBackwardFold : public TestRunnable
 {
 public:
-  SmallIndexBackwardFold()
-    : TestRunnable("small index backward for fold (3)(3)(222)", 5, 3)
+  SmallIndexBackwardFold() : TestRunnable("small index backward for fold (3)(3)(222)", 5, 3)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{1, 1, 3};
-    IntSequence nvs{3, 3, 2};
+    Symmetry s {1, 1, 3};
+    IntSequence nvs {3, 3, 2};
     return index_backward<FGSTensor>(s, nvs);
   }
 };
@@ -640,15 +626,14 @@ public:
 class IndexBackwardFold : public TestRunnable
 {
 public:
-  IndexBackwardFold()
-    : TestRunnable("index backward for fold (44)(222)(44)", 7, 4)
+  IndexBackwardFold() : TestRunnable("index backward for fold (44)(222)(44)", 7, 4)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{2, 3, 2};
-    IntSequence nvs{4, 2, 4};
+    Symmetry s {2, 3, 2};
+    IntSequence nvs {4, 2, 4};
     return index_backward<FGSTensor>(s, nvs);
   }
 };
@@ -656,15 +641,14 @@ public:
 class SmallIndexBackwardUnfold : public TestRunnable
 {
 public:
-  SmallIndexBackwardUnfold()
-    : TestRunnable("small index backward for unfold (3)(3)(222)", 5, 3)
+  SmallIndexBackwardUnfold() : TestRunnable("small index backward for unfold (3)(3)(222)", 5, 3)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{1, 1, 3};
-    IntSequence nvs{3, 3, 2};
+    Symmetry s {1, 1, 3};
+    IntSequence nvs {3, 3, 2};
     return index_backward<UGSTensor>(s, nvs);
   }
 };
@@ -672,15 +656,14 @@ public:
 class IndexBackwardUnfold : public TestRunnable
 {
 public:
-  IndexBackwardUnfold()
-    : TestRunnable("index backward for unfold (44)(222)(44)", 7, 4)
+  IndexBackwardUnfold() : TestRunnable("index backward for unfold (44)(222)(44)", 7, 4)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{2, 3, 2};
-    IntSequence nvs{4, 2, 4};
+    Symmetry s {2, 3, 2};
+    IntSequence nvs {4, 2, 4};
     return index_backward<UGSTensor>(s, nvs);
   }
 };
@@ -688,15 +671,14 @@ public:
 class SmallIndexOffsetFold : public TestRunnable
 {
 public:
-  SmallIndexOffsetFold()
-    : TestRunnable("small index offset for fold (44)(222)", 5, 4)
+  SmallIndexOffsetFold() : TestRunnable("small index offset for fold (44)(222)", 5, 4)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{2, 3};
-    IntSequence nvs{4, 2};
+    Symmetry s {2, 3};
+    IntSequence nvs {4, 2};
     return index_offset<FGSTensor>(s, nvs);
   }
 };
@@ -704,15 +686,14 @@ public:
 class SmallIndexOffsetUnfold : public TestRunnable
 {
 public:
-  SmallIndexOffsetUnfold()
-    : TestRunnable("small index offset for unfold (44)(222)", 5, 4)
+  SmallIndexOffsetUnfold() : TestRunnable("small index offset for unfold (44)(222)", 5, 4)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{2, 3};
-    IntSequence nvs{4, 2};
+    Symmetry s {2, 3};
+    IntSequence nvs {4, 2};
     return index_offset<UGSTensor>(s, nvs);
   }
 };
@@ -720,15 +701,14 @@ public:
 class IndexOffsetFold : public TestRunnable
 {
 public:
-  IndexOffsetFold()
-    : TestRunnable("index offset for fold (55)(222)(22)", 5, 5)
+  IndexOffsetFold() : TestRunnable("index offset for fold (55)(222)(22)", 5, 5)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{2, 3, 2};
-    IntSequence nvs{5, 2, 2};
+    Symmetry s {2, 3, 2};
+    IntSequence nvs {5, 2, 2};
     return index_offset<FGSTensor>(s, nvs);
   }
 };
@@ -736,15 +716,14 @@ public:
 class IndexOffsetUnfold : public TestRunnable
 {
 public:
-  IndexOffsetUnfold()
-    : TestRunnable("index offset for unfold (55)(222)(22)", 7, 5)
+  IndexOffsetUnfold() : TestRunnable("index offset for unfold (55)(222)(22)", 7, 5)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{2, 3, 2};
-    IntSequence nvs{5, 2, 2};
+    Symmetry s {2, 3, 2};
+    IntSequence nvs {5, 2, 2};
     return index_offset<UGSTensor>(s, nvs);
   }
 };
@@ -752,8 +731,7 @@ public:
 class SmallFoldUnfoldFS : public TestRunnable
 {
 public:
-  SmallFoldUnfoldFS()
-    : TestRunnable("small fold-unfold for full symmetry (444)", 3, 4)
+  SmallFoldUnfoldFS() : TestRunnable("small fold-unfold for full symmetry (444)", 3, 4)
   {
   }
   bool
@@ -766,15 +744,14 @@ public:
 class SmallFoldUnfoldGS : public TestRunnable
 {
 public:
-  SmallFoldUnfoldGS()
-    : TestRunnable("small fold-unfold for gen symmetry (3)(33)(22)", 5, 3)
+  SmallFoldUnfoldGS() : TestRunnable("small fold-unfold for gen symmetry (3)(33)(22)", 5, 3)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{1, 2, 2};
-    IntSequence nvs{3, 3, 2};
+    Symmetry s {1, 2, 2};
+    IntSequence nvs {3, 3, 2};
     return gs_fold_unfold(5, s, nvs);
   }
 };
@@ -782,8 +759,7 @@ public:
 class FoldUnfoldFS : public TestRunnable
 {
 public:
-  FoldUnfoldFS()
-    : TestRunnable("fold-unfold for full symmetry (9999)", 4, 9)
+  FoldUnfoldFS() : TestRunnable("fold-unfold for full symmetry (9999)", 4, 9)
   {
   }
   bool
@@ -796,15 +772,14 @@ public:
 class FoldUnfoldGS : public TestRunnable
 {
 public:
-  FoldUnfoldGS()
-    : TestRunnable("fold-unfold for gen symmetry (66)(2)(66)", 5, 6)
+  FoldUnfoldGS() : TestRunnable("fold-unfold for gen symmetry (66)(2)(66)", 5, 6)
   {
   }
   bool
   run() const override
   {
-    Symmetry s{2, 1, 2};
-    IntSequence nvs{6, 2, 6};
+    Symmetry s {2, 1, 2};
+    IntSequence nvs {6, 2, 6};
     return gs_fold_unfold(5, s, nvs);
   }
 };
@@ -812,8 +787,7 @@ public:
 class SmallFoldUnfoldR : public TestRunnable
 {
 public:
-  SmallFoldUnfoldR()
-    : TestRunnable("small fold-unfold for row full symmetry (333)", 3, 3)
+  SmallFoldUnfoldR() : TestRunnable("small fold-unfold for row full symmetry (333)", 3, 3)
   {
   }
   bool
@@ -826,8 +800,7 @@ public:
 class FoldUnfoldR : public TestRunnable
 {
 public:
-  FoldUnfoldR()
-    : TestRunnable("fold-unfold for row full symmetry (66666)", 5, 6)
+  FoldUnfoldR() : TestRunnable("fold-unfold for row full symmetry (66666)", 5, 6)
   {
   }
   bool
@@ -840,53 +813,49 @@ public:
 class SmallDenseProd : public TestRunnable
 {
 public:
-  SmallDenseProd()
-    : TestRunnable("small dense prod bsym=1-2,nvs=3-2,h=2-3,r=2", 3, 3)
+  SmallDenseProd() : TestRunnable("small dense prod bsym=1-2,nvs=3-2,h=2-3,r=2", 3, 3)
   {
   }
   bool
   run() const override
   {
-    IntSequence bnvs{3, 2};
-    return dense_prod(Symmetry{1, 2}, bnvs, 2, 3, 2);
+    IntSequence bnvs {3, 2};
+    return dense_prod(Symmetry {1, 2}, bnvs, 2, 3, 2);
   }
 };
 
 class DenseProd : public TestRunnable
 {
 public:
-  DenseProd()
-    : TestRunnable("dense prod bsym=2-3,nvs=10-7,h=3-15,r=10", 5, 15)
+  DenseProd() : TestRunnable("dense prod bsym=2-3,nvs=10-7,h=3-15,r=10", 5, 15)
   {
   }
   bool
   run() const override
   {
-    IntSequence bnvs{10, 7};
-    return dense_prod(Symmetry{2, 3}, bnvs, 3, 15, 10);
+    IntSequence bnvs {10, 7};
+    return dense_prod(Symmetry {2, 3}, bnvs, 3, 15, 10);
   }
 };
 
 class BigDenseProd : public TestRunnable
 {
 public:
-  BigDenseProd()
-    : TestRunnable("dense prod bsym=3-2,nvs=13-11,h=3-20,r=20", 6, 20)
+  BigDenseProd() : TestRunnable("dense prod bsym=3-2,nvs=13-11,h=3-20,r=20", 6, 20)
   {
   }
   bool
   run() const override
   {
-    IntSequence bnvs{13, 11};
-    return dense_prod(Symmetry{3, 2}, bnvs, 3, 20, 20);
+    IntSequence bnvs {13, 11};
+    return dense_prod(Symmetry {3, 2}, bnvs, 3, 20, 20);
   }
 };
 
 class SmallFoldedMonomial : public TestRunnable
 {
 public:
-  SmallFoldedMonomial()
-    : TestRunnable("folded vrs. monoms (g,x,y,u)=(10,4,5,3), dim=4", 4, 8)
+  SmallFoldedMonomial() : TestRunnable("folded vrs. monoms (g,x,y,u)=(10,4,5,3), dim=4", 4, 8)
   {
   }
   bool
@@ -899,8 +868,7 @@ public:
 class FoldedMonomial : public TestRunnable
 {
 public:
-  FoldedMonomial()
-    : TestRunnable("folded vrs. monoms (g,x,y,u)=(20,12,10,5), dim=4", 4, 15)
+  FoldedMonomial() : TestRunnable("folded vrs. monoms (g,x,y,u)=(20,12,10,5), dim=4", 4, 15)
   {
   }
   bool
@@ -913,8 +881,7 @@ public:
 class SmallUnfoldedMonomial : public TestRunnable
 {
 public:
-  SmallUnfoldedMonomial()
-    : TestRunnable("unfolded vrs. monoms (g,x,y,u)=(10,4,5,3), dim=4", 4, 8)
+  SmallUnfoldedMonomial() : TestRunnable("unfolded vrs. monoms (g,x,y,u)=(10,4,5,3), dim=4", 4, 8)
   {
   }
   bool
@@ -927,8 +894,7 @@ public:
 class UnfoldedMonomial : public TestRunnable
 {
 public:
-  UnfoldedMonomial()
-    : TestRunnable("unfolded vrs. monoms (g,x,y,u)=(20,12,10,5), dim=4", 4, 15)
+  UnfoldedMonomial() : TestRunnable("unfolded vrs. monoms (g,x,y,u)=(20,12,10,5), dim=4", 4, 15)
   {
   }
   bool
@@ -941,8 +907,7 @@ public:
 class FoldedContractionSmall : public TestRunnable
 {
 public:
-  FoldedContractionSmall()
-    : TestRunnable("folded contraction small (r=5, nv=4, dim=3)", 3, 4)
+  FoldedContractionSmall() : TestRunnable("folded contraction small (r=5, nv=4, dim=3)", 3, 4)
   {
   }
   bool
@@ -955,8 +920,7 @@ public:
 class FoldedContractionBig : public TestRunnable
 {
 public:
-  FoldedContractionBig()
-    : TestRunnable("folded contraction big (r=20, nv=12, dim=5)", 5, 12)
+  FoldedContractionBig() : TestRunnable("folded contraction big (r=20, nv=12, dim=5)", 5, 12)
   {
   }
   bool
@@ -969,8 +933,7 @@ public:
 class UnfoldedContractionSmall : public TestRunnable
 {
 public:
-  UnfoldedContractionSmall()
-    : TestRunnable("unfolded contraction small (r=5, nv=4, dim=3)", 3, 4)
+  UnfoldedContractionSmall() : TestRunnable("unfolded contraction small (r=5, nv=4, dim=3)", 3, 4)
   {
   }
   bool
@@ -983,8 +946,7 @@ public:
 class UnfoldedContractionBig : public TestRunnable
 {
 public:
-  UnfoldedContractionBig()
-    : TestRunnable("unfolded contraction big (r=20, nv=12, dim=5)", 5, 12)
+  UnfoldedContractionBig() : TestRunnable("unfolded contraction big (r=20, nv=12, dim=5)", 5, 12)
   {
   }
   bool
@@ -997,8 +959,7 @@ public:
 class PolyEvalSmall : public TestRunnable
 {
 public:
-  PolyEvalSmall()
-    : TestRunnable("polynomial evaluation small (r=4, nv=5, maxdim=4)", 4, 5)
+  PolyEvalSmall() : TestRunnable("polynomial evaluation small (r=4, nv=5, maxdim=4)", 4, 5)
   {
   }
   bool
@@ -1011,8 +972,7 @@ public:
 class PolyEvalBig : public TestRunnable
 {
 public:
-  PolyEvalBig()
-    : TestRunnable("polynomial evaluation big (r=244, nv=97, maxdim=2)", 2, 97)
+  PolyEvalBig() : TestRunnable("polynomial evaluation big (r=244, nv=97, maxdim=2)", 2, 97)
   {
   }
   bool
@@ -1025,9 +985,7 @@ public:
 class FoldZContSmall : public TestRunnable
 {
 public:
-  FoldZContSmall()
-    : TestRunnable("folded Z container (r=3,ny=2,nu=2,nup=1,G=2,g=2,dim=3)",
-                   3, 8)
+  FoldZContSmall() : TestRunnable("folded Z container (r=3,ny=2,nu=2,nup=1,G=2,g=2,dim=3)", 3, 8)
   {
   }
   bool
@@ -1040,9 +998,7 @@ public:
 class FoldZCont : public TestRunnable
 {
 public:
-  FoldZCont()
-    : TestRunnable("folded Z container (r=13,ny=5,nu=7,nup=4,G=6,g=7,dim=4)",
-                   4, 25)
+  FoldZCont() : TestRunnable("folded Z container (r=13,ny=5,nu=7,nup=4,G=6,g=7,dim=4)", 4, 25)
   {
   }
   bool
@@ -1055,9 +1011,8 @@ public:
 class UnfoldZContSmall : public TestRunnable
 {
 public:
-  UnfoldZContSmall()
-    : TestRunnable("unfolded Z container (r=3,ny=2,nu=2,nup=1,G=2,g=2,dim=3)",
-                   3, 8)
+  UnfoldZContSmall() :
+      TestRunnable("unfolded Z container (r=3,ny=2,nu=2,nup=1,G=2,g=2,dim=3)", 3, 8)
   {
   }
   bool
@@ -1070,9 +1025,7 @@ public:
 class UnfoldZCont : public TestRunnable
 {
 public:
-  UnfoldZCont()
-    : TestRunnable("unfolded Z container (r=13,ny=5,nu=7,nup=4,G=6,g=7,dim=4",
-                   4, 25)
+  UnfoldZCont() : TestRunnable("unfolded Z container (r=13,ny=5,nu=7,nup=4,G=6,g=7,dim=4", 4, 25)
   {
   }
   bool
@@ -1126,24 +1079,24 @@ main()
   /* Initialize library. We do it for each test individually instead of
      computing the maximum dimension and number of variables, because otherwise
      it does not pass the check on maximum problem size. */
-  for (const auto &test : all_tests)
+  for (const auto& test : all_tests)
     TLStatic::init(test->dim, test->nvar);
 
   // Launch the tests
   int success = 0;
-  for (const auto &test : all_tests)
+  for (const auto& test : all_tests)
     {
       try
         {
           if (test->test())
             success++;
         }
-      catch (const TLException &e)
+      catch (const TLException& e)
         {
           std::cout << "Caught TL exception in <" << test->name << ">:\n";
           e.print();
         }
-      catch (SylvException &e)
+      catch (SylvException& e)
         {
           std::cout << "Caught Sylv exception in <" << test->name << ">:\n";
           e.printMessage();
@@ -1151,8 +1104,8 @@ main()
     }
 
   int nfailed = all_tests.size() - success;
-  std::cout << "There were " << nfailed << " tests that failed out of "
-            << all_tests.size() << " tests run." << std::endl;
+  std::cout << "There were " << nfailed << " tests that failed out of " << all_tests.size()
+            << " tests run." << std::endl;
 
   if (nfailed)
     return EXIT_FAILURE;
diff --git a/mex/sources/libkorder/tl/tl_exception.hh b/mex/sources/libkorder/tl/tl_exception.hh
index e4c2d03c5345abdf6dc56c5c85c8e9cd91209f29..b67441518b219e8c99c292392f3b4032ffa14085 100644
--- a/mex/sources/libkorder/tl/tl_exception.hh
+++ b/mex/sources/libkorder/tl/tl_exception.hh
@@ -31,8 +31,8 @@
 #define TL_EXCEPTION_H
 
 #include <iostream>
-#include <utility>
 #include <string>
+#include <utility>
 
 /* The basic idea of raising an exception if some condition fails is that the
    conditions is checked only if required. We define global TL_DEBUG macro
@@ -59,11 +59,11 @@
 # define TL_DEBUG 0
 #endif
 
-#define TL_RAISE(mes)                           \
-  throw TLException(__FILE__, __LINE__, mes)
+#define TL_RAISE(mes) throw TLException(__FILE__, __LINE__, mes)
 
-#define TL_RAISE_IF(expr, mes)                                          \
-  if (TL_DEBUG >= TL_DEBUG_EXCEPTION && (expr)) throw TLException(__FILE__, __LINE__, mes);
+#define TL_RAISE_IF(expr, mes)                                                                     \
+ if (TL_DEBUG >= TL_DEBUG_EXCEPTION && (expr))                                                     \
+  throw TLException(__FILE__, __LINE__, mes);
 
 /* Primitive exception class containing file name, line number and message. */
 
@@ -71,12 +71,11 @@ class TLException
 {
   const std::string fname;
   int lnum;
+
 public:
   const std::string message;
-  TLException(std::string fname_arg, int lnum_arg, std::string message_arg)
-    : fname{std::move(fname_arg)},
-      lnum{lnum_arg},
-      message{std::move(message_arg)}
+  TLException(std::string fname_arg, int lnum_arg, std::string message_arg) :
+      fname {std::move(fname_arg)}, lnum {lnum_arg}, message {std::move(message_arg)}
   {
   }
   virtual ~TLException() = default;
diff --git a/mex/sources/libkorder/tl/tl_static.cc b/mex/sources/libkorder/tl/tl_static.cc
index f1adb8c48f09666970a2d8608ce4adfbca5f77f3..5d7bd04775ca265b899b0d02ae551cbb7b9cc4e4 100644
--- a/mex/sources/libkorder/tl/tl_static.cc
+++ b/mex/sources/libkorder/tl/tl_static.cc
@@ -22,42 +22,43 @@
 #include "pascal_triangle.hh"
 #include "tl_exception.hh"
 
-#include <mutex>
-#include <limits>
 #include <cmath>
+#include <limits>
+#include <mutex>
 
 /* Note that we allow for repeated calls of init(). This is not normal
    and the only purpose of allowing this is the test suite. */
 
 namespace TLStatic
 {
-  EquivalenceBundle ebundle(1);
-  PermutationBundle pbundle(1);
-  std::mutex mut;
-
-  const EquivalenceSet &
-  getEquiv(int n)
-  {
-    return ebundle.get(n);
-  }
-
-  const PermutationSet &
-  getPerm(int n)
-  {
-    return pbundle.get(n);
-  }
-
-  void
-  init(int dim, int nvar)
-  {
-    // Check that tensor indices will not overflow (they are stored as signed int, hence on 31 bits)
-    if (std::log2(nvar)*dim >= std::numeric_limits<int>::digits)
-      throw TLException(__FILE__, __LINE__, "Problem too large, you should decrease the approximation order");
-
-    std::lock_guard<std::mutex>{mut};
-    ebundle.generateUpTo(dim);
-    pbundle.generateUpTo(dim);
-
-    PascalTriangle::ensure(nvar, dim);
-  }
+EquivalenceBundle ebundle(1);
+PermutationBundle pbundle(1);
+std::mutex mut;
+
+const EquivalenceSet&
+getEquiv(int n)
+{
+  return ebundle.get(n);
+}
+
+const PermutationSet&
+getPerm(int n)
+{
+  return pbundle.get(n);
+}
+
+void
+init(int dim, int nvar)
+{
+  // Check that tensor indices will not overflow (they are stored as signed int, hence on 31 bits)
+  if (std::log2(nvar) * dim >= std::numeric_limits<int>::digits)
+    throw TLException(__FILE__, __LINE__,
+                      "Problem too large, you should decrease the approximation order");
+
+  std::lock_guard<std::mutex> {mut};
+  ebundle.generateUpTo(dim);
+  pbundle.generateUpTo(dim);
+
+  PascalTriangle::ensure(nvar, dim);
+}
 }
diff --git a/mex/sources/libkorder/tl/tl_static.hh b/mex/sources/libkorder/tl/tl_static.hh
index 19511c34b069bc1398643488882ccff081a44ad7..55a1aef001d773f3d0487b4e2008a6abd4ac60e9 100644
--- a/mex/sources/libkorder/tl/tl_static.hh
+++ b/mex/sources/libkorder/tl/tl_static.hh
@@ -37,9 +37,9 @@
 
 namespace TLStatic
 {
-  const EquivalenceSet &getEquiv(int n);
-  const PermutationSet &getPerm(int n);
-  void init(int dim, int nvar);
+const EquivalenceSet& getEquiv(int n);
+const PermutationSet& getPerm(int n);
+void init(int dim, int nvar);
 };
 
 #endif
diff --git a/mex/sources/libkorder/tl/twod_matrix.cc b/mex/sources/libkorder/tl/twod_matrix.cc
index 1e308dc08fc9b1437b308d52814604c45cb816b2..2c25f03b745e88d112d4964c3989c45dd5639a29 100644
--- a/mex/sources/libkorder/tl/twod_matrix.cc
+++ b/mex/sources/libkorder/tl/twod_matrix.cc
@@ -21,38 +21,37 @@
 #include "twod_matrix.hh"
 #include "tl_exception.hh"
 
-#include <memory>
 #include <fstream>
 #include <iomanip>
 #include <limits>
+#include <memory>
 
-ConstTwoDMatrix::ConstTwoDMatrix(const TwoDMatrix &m)
-  : ConstGeneralMatrix(m)
+ConstTwoDMatrix::ConstTwoDMatrix(const TwoDMatrix& m) : ConstGeneralMatrix(m)
 {
 }
 
-ConstTwoDMatrix::ConstTwoDMatrix(const TwoDMatrix &m, int first_col, int num)
-  : ConstGeneralMatrix(m, 0, first_col, m.nrows(), num)
+ConstTwoDMatrix::ConstTwoDMatrix(const TwoDMatrix& m, int first_col, int num) :
+    ConstGeneralMatrix(m, 0, first_col, m.nrows(), num)
 {
 }
 
-ConstTwoDMatrix::ConstTwoDMatrix(const ConstTwoDMatrix &m, int first_col, int num)
-  : ConstGeneralMatrix(m, 0, first_col, m.nrows(), num)
+ConstTwoDMatrix::ConstTwoDMatrix(const ConstTwoDMatrix& m, int first_col, int num) :
+    ConstGeneralMatrix(m, 0, first_col, m.nrows(), num)
 {
 }
 
-ConstTwoDMatrix::ConstTwoDMatrix(int first_row, int num, const TwoDMatrix &m)
-  : ConstGeneralMatrix(m, first_row, 0, num, m.ncols())
+ConstTwoDMatrix::ConstTwoDMatrix(int first_row, int num, const TwoDMatrix& m) :
+    ConstGeneralMatrix(m, first_row, 0, num, m.ncols())
 {
 }
 
-ConstTwoDMatrix::ConstTwoDMatrix(int first_row, int num, const ConstTwoDMatrix &m)
-  : ConstGeneralMatrix(m, first_row, 0, num, m.ncols())
+ConstTwoDMatrix::ConstTwoDMatrix(int first_row, int num, const ConstTwoDMatrix& m) :
+    ConstGeneralMatrix(m, first_row, 0, num, m.ncols())
 {
 }
 
-TwoDMatrix &
-TwoDMatrix::operator=(const ConstTwoDMatrix &m)
+TwoDMatrix&
+TwoDMatrix::operator=(const ConstTwoDMatrix& m)
 {
   GeneralMatrix::operator=(m);
   return *this;
@@ -66,13 +65,13 @@ TwoDMatrix::copyRow(int from, int to)
 }
 
 void
-TwoDMatrix::copyRow(const ConstTwoDMatrix &m, int from, int to)
+TwoDMatrix::copyRow(const ConstTwoDMatrix& m, int from, int to)
 {
   getRow(to) = m.getRow(from);
 }
 
 void
-TwoDMatrix::addRow(double d, const ConstTwoDMatrix &m, int from, int to)
+TwoDMatrix::addRow(double d, const ConstTwoDMatrix& m, int from, int to)
 {
   getRow(to).add(d, m.getRow(from));
 }
@@ -85,21 +84,21 @@ TwoDMatrix::copyColumn(int from, int to)
 }
 
 void
-TwoDMatrix::copyColumn(const ConstTwoDMatrix &m, int from, int to)
+TwoDMatrix::copyColumn(const ConstTwoDMatrix& m, int from, int to)
 {
   getCol(to) = m.getCol(from);
 }
 
 void
-TwoDMatrix::addColumn(double d, const ConstTwoDMatrix &m, int from, int to)
+TwoDMatrix::addColumn(double d, const ConstTwoDMatrix& m, int from, int to)
 {
   getCol(to).add(d, m.getCol(from));
 }
 
 void
-TwoDMatrix::save(const std::string &fname) const
+TwoDMatrix::save(const std::string& fname) const
 {
-  std::ofstream fd{fname, std::ios::out | std::ios::trunc};
+  std::ofstream fd {fname, std::ios::out | std::ios::trunc};
   if (fd.fail())
     TL_RAISE("Cannot open file for writing in TwoDMatrix::save");
 
diff --git a/mex/sources/libkorder/tl/twod_matrix.hh b/mex/sources/libkorder/tl/twod_matrix.hh
index 728a7691ce27fa64a7092dbacd4cde3077d7ec2b..674d0dc600415c7efac746e8c1bd567c45eafa70 100644
--- a/mex/sources/libkorder/tl/twod_matrix.hh
+++ b/mex/sources/libkorder/tl/twod_matrix.hh
@@ -42,160 +42,152 @@ class TwoDMatrix;
 class ConstTwoDMatrix : public ConstGeneralMatrix
 {
 public:
-  ConstTwoDMatrix(int m, int n, ConstVector d)
-    : ConstGeneralMatrix(std::move(d), m, n)
+  ConstTwoDMatrix(int m, int n, ConstVector d) : ConstGeneralMatrix(std::move(d), m, n)
   {
   }
-  ConstTwoDMatrix(const ConstTwoDMatrix &m) = default;
-  ConstTwoDMatrix(ConstTwoDMatrix &&m) = default;
+  ConstTwoDMatrix(const ConstTwoDMatrix& m) = default;
+  ConstTwoDMatrix(ConstTwoDMatrix&& m) = default;
 
   // Implicit conversion from TwoDMatrix is ok, since it's cheap
-  ConstTwoDMatrix(const TwoDMatrix &m);
+  ConstTwoDMatrix(const TwoDMatrix& m);
 
   // Constructors creating a submatrix of consecutive columns
-  ConstTwoDMatrix(const TwoDMatrix &m, int first_col, int num);
-  ConstTwoDMatrix(const ConstTwoDMatrix &m, int first_col, int num);
+  ConstTwoDMatrix(const TwoDMatrix& m, int first_col, int num);
+  ConstTwoDMatrix(const ConstTwoDMatrix& m, int first_col, int num);
 
   // Constructors creating a submatrix of consecutive rows
-  ConstTwoDMatrix(int first_row, int num, const TwoDMatrix &m);
-  ConstTwoDMatrix(int first_row, int num, const ConstTwoDMatrix &m);
+  ConstTwoDMatrix(int first_row, int num, const TwoDMatrix& m);
+  ConstTwoDMatrix(int first_row, int num, const ConstTwoDMatrix& m);
 
-  ConstTwoDMatrix(const ConstTwoDMatrix &m, int first_row, int first_col, int rows, int cols)
-    : ConstGeneralMatrix(m, first_row, first_col, rows, cols)
+  ConstTwoDMatrix(const ConstTwoDMatrix& m, int first_row, int first_col, int rows, int cols) :
+      ConstGeneralMatrix(m, first_row, first_col, rows, cols)
   {
   }
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-  explicit ConstTwoDMatrix(const mxArray *p) : ConstGeneralMatrix(p)
+  explicit ConstTwoDMatrix(const mxArray* p) : ConstGeneralMatrix(p)
   {
   }
 #endif
   ~ConstTwoDMatrix() override = default;
 
-  ConstTwoDMatrix &operator=(const ConstTwoDMatrix &v) = delete;
-  ConstTwoDMatrix &operator=(ConstTwoDMatrix &&v) = delete;
+  ConstTwoDMatrix& operator=(const ConstTwoDMatrix& v) = delete;
+  ConstTwoDMatrix& operator=(ConstTwoDMatrix&& v) = delete;
 };
 
 class TwoDMatrix : public GeneralMatrix
 {
 public:
-  TwoDMatrix(const TwoDMatrix &m) = default;
-  TwoDMatrix(TwoDMatrix &&m) = default;
-  TwoDMatrix(int r, int c)
-    : GeneralMatrix(r, c)
+  TwoDMatrix(const TwoDMatrix& m) = default;
+  TwoDMatrix(TwoDMatrix&& m) = default;
+  TwoDMatrix(int r, int c) : GeneralMatrix(r, c)
   {
   }
-  TwoDMatrix(int r, int c, Vector d)
-    : GeneralMatrix(std::move(d), r, c)
+  TwoDMatrix(int r, int c, Vector d) : GeneralMatrix(std::move(d), r, c)
   {
   }
-  TwoDMatrix(const GeneralMatrix &m)
-    : GeneralMatrix(m)
+  TwoDMatrix(const GeneralMatrix& m) : GeneralMatrix(m)
   {
   }
   // We don't want implict conversion from ConstGeneralMatrix, since it's expensive
-  explicit TwoDMatrix(const ConstGeneralMatrix &m)
-    : GeneralMatrix(m)
+  explicit TwoDMatrix(const ConstGeneralMatrix& m) : GeneralMatrix(m)
   {
   }
   template<class T>
-  explicit TwoDMatrix(const TransposedMatrix<T> &m)
-    : GeneralMatrix(m)
+  explicit TwoDMatrix(const TransposedMatrix<T>& m) : GeneralMatrix(m)
   {
   }
   // Select only some columns (with data copy)
-  TwoDMatrix(const TwoDMatrix &m, int first_col, int num)
-    : GeneralMatrix(m, 0, first_col, m.nrows(), num)
+  TwoDMatrix(const TwoDMatrix& m, int first_col, int num) :
+      GeneralMatrix(m, 0, first_col, m.nrows(), num)
   {
   }
   // Select only some columns (with data sharing)
-  TwoDMatrix(TwoDMatrix &m, int first_col, int num)
-    : GeneralMatrix(m, 0, first_col, m.nrows(), num)
+  TwoDMatrix(TwoDMatrix& m, int first_col, int num) : GeneralMatrix(m, 0, first_col, m.nrows(), num)
   {
   }
   // Select only some rows (with data copy)
-  TwoDMatrix(int first_row, int num, const TwoDMatrix &m)
-    : GeneralMatrix(m, first_row, 0, num, m.ncols())
+  TwoDMatrix(int first_row, int num, const TwoDMatrix& m) :
+      GeneralMatrix(m, first_row, 0, num, m.ncols())
   {
   }
   // Select only some rows (with data sharing)
-  TwoDMatrix(int first_row, int num, TwoDMatrix &m)
-    : GeneralMatrix(m, first_row, 0, num, m.ncols())
+  TwoDMatrix(int first_row, int num, TwoDMatrix& m) : GeneralMatrix(m, first_row, 0, num, m.ncols())
   {
   }
   // Select a submatrix (with data sharing)
-  TwoDMatrix(TwoDMatrix &m, int first_row, int first_col, int rows, int cols)
-    : GeneralMatrix(m, first_row, first_col, rows, cols)
+  TwoDMatrix(TwoDMatrix& m, int first_row, int first_col, int rows, int cols) :
+      GeneralMatrix(m, first_row, first_col, rows, cols)
   {
   }
   // Select a submatrix (with data copy)
-  TwoDMatrix(const TwoDMatrix &m, int first_row, int first_col, int rows, int cols)
-    : GeneralMatrix(m, first_row, first_col, rows, cols)
+  TwoDMatrix(const TwoDMatrix& m, int first_row, int first_col, int rows, int cols) :
+      GeneralMatrix(m, first_row, first_col, rows, cols)
   {
   }
 
 #if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
-  explicit TwoDMatrix(mxArray *p) : GeneralMatrix(p)
+  explicit TwoDMatrix(mxArray* p) : GeneralMatrix(p)
   {
   }
 #endif
   ~TwoDMatrix() override = default;
 
-  TwoDMatrix &operator=(const TwoDMatrix &m) = default;
-  TwoDMatrix &operator=(TwoDMatrix &&m) = default;
-  TwoDMatrix &operator=(const ConstTwoDMatrix &m);
+  TwoDMatrix& operator=(const TwoDMatrix& m) = default;
+  TwoDMatrix& operator=(TwoDMatrix&& m) = default;
+  TwoDMatrix& operator=(const ConstTwoDMatrix& m);
 
   // TwoDMatrix row methods declarations
   void copyRow(int from, int to);
-  void copyRow(const ConstTwoDMatrix &m, int from, int to);
+  void copyRow(const ConstTwoDMatrix& m, int from, int to);
   void
-  copyRow(const TwoDMatrix &m, int from, int to)
+  copyRow(const TwoDMatrix& m, int from, int to)
   {
     copyRow(ConstTwoDMatrix(m), from, to);
   }
   void
-  addRow(const ConstTwoDMatrix &m, int from, int to)
+  addRow(const ConstTwoDMatrix& m, int from, int to)
   {
     addRow(1.0, m, from, to);
   }
   void
-  addRow(const TwoDMatrix &m, int from, int to)
+  addRow(const TwoDMatrix& m, int from, int to)
   {
     addRow(1.0, ConstTwoDMatrix(m), from, to);
   }
-  void addRow(double d, const ConstTwoDMatrix &m, int from, int to);
+  void addRow(double d, const ConstTwoDMatrix& m, int from, int to);
   void
-  addRow(double d, const TwoDMatrix &m, int from, int to)
+  addRow(double d, const TwoDMatrix& m, int from, int to)
   {
     addRow(d, ConstTwoDMatrix(m), from, to);
   }
 
   // TwoDMatrix column methods declarations
   void copyColumn(int from, int to);
-  void copyColumn(const ConstTwoDMatrix &m, int from, int to);
+  void copyColumn(const ConstTwoDMatrix& m, int from, int to);
   void
-  copyColumn(const TwoDMatrix &m, int from, int to)
+  copyColumn(const TwoDMatrix& m, int from, int to)
   {
     copyColumn(ConstTwoDMatrix(m), from, to);
   }
   void
-  addColumn(const ConstTwoDMatrix &m, int from, int to)
+  addColumn(const ConstTwoDMatrix& m, int from, int to)
   {
     addColumn(1.0, ConstTwoDMatrix(m), from, to);
   }
   void
-  addColumn(const TwoDMatrix &m, int from, int to)
+  addColumn(const TwoDMatrix& m, int from, int to)
   {
     addColumn(1.0, ConstTwoDMatrix(m), from, to);
   }
-  void addColumn(double d, const ConstTwoDMatrix &m, int from, int to);
+  void addColumn(double d, const ConstTwoDMatrix& m, int from, int to);
   void
-  addColumn(double d, const TwoDMatrix &m, int from, int to)
+  addColumn(double d, const TwoDMatrix& m, int from, int to)
   {
     addColumn(d, ConstTwoDMatrix(m), from, to);
   }
 
   // Saves the matrix to a text file
-  void save(const std::string &fname) const;
+  void save(const std::string& fname) const;
 };
 
 #endif
diff --git a/mex/sources/libkorder/utils/dynare_exception.hh b/mex/sources/libkorder/utils/dynare_exception.hh
index d86466b484fa081d74b2461b08b6adff28dce9d3..b0ad2cff4bd9388faae83b6e32a3efbee6e0a98f 100644
--- a/mex/sources/libkorder/utils/dynare_exception.hh
+++ b/mex/sources/libkorder/utils/dynare_exception.hh
@@ -27,21 +27,22 @@
 class DynareException
 {
   std::string mes;
+
 public:
-  DynareException(const std::string &m, const std::string &fname, int line, int col)
-    : mes{"Parse error at " + fname + ", line " + std::to_string(line) + ", column "
-          + std::to_string(col) + ": " + m}
+  DynareException(const std::string& m, const std::string& fname, int line, int col) :
+      mes {"Parse error at " + fname + ", line " + std::to_string(line) + ", column "
+           + std::to_string(col) + ": " + m}
   {
   }
-  DynareException(const std::string &fname, int line, const std::string &m)
-    : mes{fname + ':' + std::to_string(line) + ": " + m}
+  DynareException(const std::string& fname, int line, const std::string& m) :
+      mes {fname + ':' + std::to_string(line) + ": " + m}
   {
   }
-  DynareException(const std::string &m, int offset)
-    : mes{"Parse error in provided string at offset " + std::to_string(offset) + ": " + m}
+  DynareException(const std::string& m, int offset) :
+      mes {"Parse error in provided string at offset " + std::to_string(offset) + ": " + m}
   {
   }
-  const std::string &
+  const std::string&
   message() const
   {
     return mes;
diff --git a/mex/sources/libkorder/utils/exception.hh b/mex/sources/libkorder/utils/exception.hh
index c0b33338e9eb5618e3aeda30dab700fa680a15ac..5eb8f9b01889a32aade6bb8528da2a33750f0f62 100644
--- a/mex/sources/libkorder/utils/exception.hh
+++ b/mex/sources/libkorder/utils/exception.hh
@@ -21,46 +21,45 @@
 #ifndef OGU_EXCEPTION_H
 #define OGU_EXCEPTION_H
 
-#include <string>
 #include <iostream>
+#include <string>
 #include <utility>
 
 namespace ogu
 {
-  /** A primitive exception. */
-  class Exception
+/** A primitive exception. */
+class Exception
+{
+protected:
+  const std::string file;
+  const int line;
+  const std::string mes;
+
+public:
+  Exception(std::string file_arg, int line_arg, std::string mes_arg) :
+      file {std::move(file_arg)}, line {line_arg}, mes {std::move(mes_arg)}
   {
-  protected:
-    const std::string file;
-    const int line;
-    const std::string mes;
-  public:
-    Exception(std::string file_arg, int line_arg, std::string mes_arg)
-      : file{std::move(file_arg)},
-        line{line_arg},
-        mes{std::move(mes_arg)}
-    {
-    }
-    virtual ~Exception() = default;
+  }
+  virtual ~Exception() = default;
 
-    void
-    print(std::ostream &out) const
-    {
-      out << file << ':' << line << ": " << mes << std::endl;
-    }
+  void
+  print(std::ostream& out) const
+  {
+    out << file << ':' << line << ": " << mes << std::endl;
+  }
 
-    void
-    print() const
-    {
-      print(std::cout);
-    }
+  void
+  print() const
+  {
+    print(std::cout);
+  }
 
-    std::string
-    message() const
-    {
-      return mes;
-    }
-  };
+  std::string
+  message() const
+  {
+    return mes;
+  }
+};
 };
 
 #endif
diff --git a/mex/sources/libkorder/utils/pascal_triangle.cc b/mex/sources/libkorder/utils/pascal_triangle.cc
index e8e0cc6df601b7d711ded0f2c47fe6ab87d66d7e..e0693ab216f00bc29010da3207663d26f2242ca1 100644
--- a/mex/sources/libkorder/utils/pascal_triangle.cc
+++ b/mex/sources/libkorder/utils/pascal_triangle.cc
@@ -24,7 +24,7 @@
 #include <mutex>
 
 void
-PascalRow::setFromPrevious(const PascalRow &prev)
+PascalRow::setFromPrevious(const PascalRow& prev)
 {
   k = prev.k + 1;
   clear();
@@ -39,10 +39,10 @@ PascalRow::setFromPrevious(const PascalRow &prev)
    other items from the provided row which must be the one with k-1.
  */
 void
-PascalRow::prolong(const PascalRow &prev)
+PascalRow::prolong(const PascalRow& prev)
 {
   if (size() == 0)
-    push_back(k+1);
+    push_back(k + 1);
   int last = back();
   for (unsigned int i = size(); i < prev.size(); i++)
     {
@@ -55,7 +55,7 @@ void
 PascalRow::prolongFirst(int n)
 {
   // TODO: check n = 1
-  for (int i = static_cast<int>(size())+2; i <= n; i++)
+  for (int i = static_cast<int>(size()) + 2; i <= n; i++)
     push_back(i);
 }
 
@@ -70,63 +70,63 @@ PascalRow::print() const
 
 namespace PascalTriangle
 {
-  namespace // Anonymous namespace that is a functional equivalent of “private”
-  {
-    std::vector<PascalRow> tr(1);
-    std::mutex mut; // For protecting the triangle from concurrent modifications
+namespace // Anonymous namespace that is a functional equivalent of “private”
+{
+std::vector<PascalRow> tr(1);
+std::mutex mut; // For protecting the triangle from concurrent modifications
 
-    int
-    max_n()
+int
+max_n()
+{
+  return static_cast<int>(tr[0].size() + 1);
+}
+
+int
+max_k()
+{
+  return static_cast<int>(tr.size());
+}
+}
+
+void
+ensure(int n, int k)
+{
+  // Add along n
+  if (n > max_n())
     {
-      return static_cast<int>(tr[0].size()+1);
+      std::lock_guard<std::mutex> lk {mut};
+      tr[0].prolongFirst(n);
+      for (int i = 2; i <= max_k(); i++)
+        tr[i - 1].prolong(tr[i - 2]);
     }
 
-    int
-    max_k()
+  if (k > max_k())
     {
-      return static_cast<int>(tr.size());
+      std::lock_guard<std::mutex> lk {mut};
+      for (int i = max_k() + 1; i <= k; i++)
+        {
+          tr.emplace_back();
+          tr.back().setFromPrevious(tr[i - 2]);
+        }
     }
-  }
-
-  void
-  ensure(int n, int k)
-  {
-    // Add along n
-    if (n > max_n())
-      {
-        std::lock_guard<std::mutex> lk{mut};
-        tr[0].prolongFirst(n);
-        for (int i = 2; i <= max_k(); i++)
-          tr[i-1].prolong(tr[i-2]);
-      }
-
-    if (k > max_k())
-      {
-        std::lock_guard<std::mutex> lk{mut};
-        for (int i = max_k()+1; i <= k; i++)
-          {
-            tr.emplace_back();
-            tr.back().setFromPrevious(tr[i-2]);
-          }
-      }
-  }
+}
 
-  int
-  noverk(int n, int k)
-  {
-    // TODO: raise exception if out of bounds
-    if (n-k < k)
-      k = n-k;
-    if (k == 0)
-      return 1;
-    ensure(n, k);
-    return (tr[k-1])[n-1-k];
-  }
+int
+noverk(int n, int k)
+{
+  // TODO: raise exception if out of bounds
+  if (n - k < k)
+    k = n - k;
+  if (k == 0)
+    return 1;
+  ensure(n, k);
+  return (tr[k - 1])[n - 1 - k];
+}
 
-  void
-  print()
-  {
-    for (const auto &i : tr)
-      i.print();
-  }
+void
+print()
+{
+  for (const auto& i : tr)
+    i.print();
+}
 }
diff --git a/mex/sources/libkorder/utils/pascal_triangle.hh b/mex/sources/libkorder/utils/pascal_triangle.hh
index cfd81d314dd41b9b4f73220a504b113b9a5bfbf7..736a46b0dddff2e5766901bbb9fcd1ce47f87c77 100644
--- a/mex/sources/libkorder/utils/pascal_triangle.hh
+++ b/mex/sources/libkorder/utils/pascal_triangle.hh
@@ -25,26 +25,27 @@
 
 class PascalRow : public std::vector<int>
 {
-  int k{1};
+  int k {1};
+
 public:
-  PascalRow() : std::vector<int>{}
+  PascalRow() : std::vector<int> {}
   {
     push_back(2);
   }
-  void setFromPrevious(const PascalRow &prev);
-  void prolong(const PascalRow &prev);
+  void setFromPrevious(const PascalRow& prev);
+  void prolong(const PascalRow& prev);
   void prolongFirst(int n);
   void print() const;
 };
 
 namespace PascalTriangle
 {
-  void ensure(int n, int k);
-  /*                              ⎛n⎞
-    Computes binomial coefficient ⎝k⎠, hence the function name (“n over k”).
-  */
-  int noverk(int n, int k);
-  void print();
+void ensure(int n, int k);
+/*                              ⎛n⎞
+  Computes binomial coefficient ⎝k⎠, hence the function name (“n over k”).
+*/
+int noverk(int n, int k);
+void print();
 };
 
 #endif
diff --git a/mex/sources/libkorder/utils/sthread.cc b/mex/sources/libkorder/utils/sthread.cc
index 65294d679f170dd855b18e405ab18372a522e69e..d722e1d1be3eea86804d96674f3cd5f4ab126d03 100644
--- a/mex/sources/libkorder/utils/sthread.cc
+++ b/mex/sources/libkorder/utils/sthread.cc
@@ -24,49 +24,49 @@
 
 namespace sthread
 {
-  /* We set the default value for ‘max_parallel_threads’ to half the number of
-     logical CPUs */
-  int
-  default_threads_number()
-  {
-    return std::max(1, static_cast<int>(std::thread::hardware_concurrency()) / 2);
-  }
+/* We set the default value for ‘max_parallel_threads’ to half the number of
+   logical CPUs */
+int
+default_threads_number()
+{
+  return std::max(1, static_cast<int>(std::thread::hardware_concurrency()) / 2);
+}
 
-  int detach_thread_group::max_parallel_threads = default_threads_number();
+int detach_thread_group::max_parallel_threads = default_threads_number();
 
-  /* We cycle through all threads in the group, and in each cycle we wait for
-     the change in the ‘counter’. If the counter indicates less than maximum
-     parallel threads running, then a new thread is run, and the iterator in
-     the list is moved.
+/* We cycle through all threads in the group, and in each cycle we wait for
+   the change in the ‘counter’. If the counter indicates less than maximum
+   parallel threads running, then a new thread is run, and the iterator in
+   the list is moved.
 
-     At the end we have to wait for all thread to finish. */
-  void
-  detach_thread_group::run()
-  {
-    std::unique_lock<std::mutex> lk{mut_cv};
-    auto it = tlist.begin();
-    while (it != tlist.end())
-      {
-        counter++;
-        std::thread th{[&, it] {
-                         // The ‘it’ variable is captured by value, because otherwise the iterator may move
-                         (*it)->operator()(mut_threads);
-                         std::unique_lock<std::mutex> lk2{mut_cv};
-                         counter--;
-                         /* First notify the thread waiting on the condition variable, then
-                            unlock the mutex. We must do these two operations in that order,
-                            otherwise there is a possibility of having the main process
-                            destroying the condition variable before the thread tries to
-                            notify it (if all other threads terminate at the same time and
-                            bring the counter down to zero).
-                            For that reason, we cannot use std::notify_all_at_thread_exit() */
-                         cv.notify_one();
-                         lk2.unlock();
-                       }};
-        th.detach();
-        ++it;
-        cv.wait(lk, [&] { return counter < max_parallel_threads; });
-      }
-    cv.wait(lk, [&] { return counter == 0; });
-  }
+   At the end we have to wait for all thread to finish. */
+void
+detach_thread_group::run()
+{
+  std::unique_lock<std::mutex> lk {mut_cv};
+  auto it = tlist.begin();
+  while (it != tlist.end())
+    {
+      counter++;
+      std::thread th {[&, it] {
+        // The ‘it’ variable is captured by value, because otherwise the iterator may move
+        (*it)->operator()(mut_threads);
+        std::unique_lock<std::mutex> lk2 {mut_cv};
+        counter--;
+        /* First notify the thread waiting on the condition variable, then
+           unlock the mutex. We must do these two operations in that order,
+           otherwise there is a possibility of having the main process
+           destroying the condition variable before the thread tries to
+           notify it (if all other threads terminate at the same time and
+           bring the counter down to zero).
+           For that reason, we cannot use std::notify_all_at_thread_exit() */
+        cv.notify_one();
+        lk2.unlock();
+      }};
+      th.detach();
+      ++it;
+      cv.wait(lk, [&] { return counter < max_parallel_threads; });
+    }
+  cv.wait(lk, [&] { return counter == 0; });
+}
 }
diff --git a/mex/sources/libkorder/utils/sthread.hh b/mex/sources/libkorder/utils/sthread.hh
index 41315e88d1efb263579dbf92c125199016e415ca..77813a57f1409c09ff0f007950932d1371a0c8c0 100644
--- a/mex/sources/libkorder/utils/sthread.hh
+++ b/mex/sources/libkorder/utils/sthread.hh
@@ -41,45 +41,45 @@
 #ifndef STHREAD_H
 #define STHREAD_H
 
-#include <vector>
+#include <condition_variable>
 #include <map>
 #include <memory>
-#include <utility>
-#include <thread>
 #include <mutex>
-#include <condition_variable>
+#include <thread>
+#include <utility>
+#include <vector>
 
 namespace sthread
 {
-  class detach_thread
-  {
-  public:
-    virtual ~detach_thread() = default;
-    virtual void operator()(std::mutex &mut) = 0;
-  };
+class detach_thread
+{
+public:
+  virtual ~detach_thread() = default;
+  virtual void operator()(std::mutex& mut) = 0;
+};
 
-  class detach_thread_group
-  {
-    std::vector<std::unique_ptr<detach_thread>> tlist;
-    std::mutex mut_cv; // For the condition variable and the counter
-    std::condition_variable cv;
-    int counter{0};
-    std::mutex mut_threads; // Passed to the workers and shared between them
-  public:
-    static int max_parallel_threads;
+class detach_thread_group
+{
+  std::vector<std::unique_ptr<detach_thread>> tlist;
+  std::mutex mut_cv; // For the condition variable and the counter
+  std::condition_variable cv;
+  int counter {0};
+  std::mutex mut_threads; // Passed to the workers and shared between them
+public:
+  static int max_parallel_threads;
 
-    void
-    insert(std::unique_ptr<detach_thread> c)
-    {
-      tlist.push_back(std::move(c));
-    }
+  void
+  insert(std::unique_ptr<detach_thread> c)
+  {
+    tlist.push_back(std::move(c));
+  }
 
-    ~detach_thread_group() = default;
+  ~detach_thread_group() = default;
 
-    void run();
-  };
+  void run();
+};
 
-  int default_threads_number();
+int default_threads_number();
 };
 
 #endif
diff --git a/mex/sources/local_state_space_iterations/local_state_space_iteration_2.cc b/mex/sources/local_state_space_iterations/local_state_space_iteration_2.cc
index cd0253ca5267cb4e2fcf8a6ec8544d2acdc28e4b..73d08fa645e2fda545aca8956a7f68ac1b3c82e5 100644
--- a/mex/sources/local_state_space_iterations/local_state_space_iteration_2.cc
+++ b/mex/sources/local_state_space_iterations/local_state_space_iteration_2.cc
@@ -22,13 +22,13 @@
  * using a second order approximation of the nonlinear state space model.
  */
 
-#include <vector>
 #include <algorithm>
-#include <tuple>
 #include <string>
+#include <tuple>
+#include <vector>
 
-#include <dynmex.h>
 #include <dynblas.h>
+#include <dynmex.h>
 
 #include <omp.h>
 
@@ -38,12 +38,12 @@
   N.B.: Under MATLAB, this only works in single-threaded mode, otherwise one
   gets a crash (because of the incompatibility between Intel and GNU OpenMPs).
 */
-//#define USE_BLAS_AT_FIRST_ORDER
+// #define USE_BLAS_AT_FIRST_ORDER
 
 std::tuple<std::vector<int>, std::vector<int>, std::vector<int>>
 set_vector_of_indices(int n, int r)
 {
-  int m = n*(n+1)/2;
+  int m = n * (n + 1) / 2;
   std::vector<int> v1(m, 0), v2(m, 0), v3(m, 0);
   for (int i = 0, index = 0, jndex = 0; i < n; i++)
     {
@@ -52,17 +52,18 @@ set_vector_of_indices(int n, int r)
         {
           v1[index] = i;
           v2[index] = j;
-          v3[index] = jndex*r;
+          v3[index] = jndex * r;
         }
     }
-  return { v1, v2, v3 };
+  return {v1, v2, v3};
 }
 
 void
-ss2Iteration_pruning(double *y2, double *y1, const double *yhat2, const double *yhat1, const double *epsilon,
-                     const double *ghx, const double *ghu,
-                     const double *constant, const double *ghxx, const double *ghuu, const double *ghxu, const double *ss,
-                     blas_int m, blas_int n, blas_int q, blas_int s, int number_of_threads)
+ss2Iteration_pruning(double* y2, double* y1, const double* yhat2, const double* yhat1,
+                     const double* epsilon, const double* ghx, const double* ghu,
+                     const double* constant, const double* ghxx, const double* ghuu,
+                     const double* ghxu, const double* ss, blas_int m, blas_int n, blas_int q,
+                     blas_int s, int number_of_threads)
 {
 #ifdef USE_BLAS_AT_FIRST_ORDER
   const double one = 1.0;
@@ -73,9 +74,9 @@ ss2Iteration_pruning(double *y2, double *y1, const double *yhat2, const double *
 #pragma omp parallel for num_threads(number_of_threads)
   for (int particle = 0; particle < s; particle++)
     {
-      int particle_ = particle*m;
-      int particle__ = particle*n;
-      int particle___ = particle*q;
+      int particle_ = particle * m;
+      int particle__ = particle * n;
+      int particle___ = particle * q;
       std::copy_n(constant, m, &y2[particle_]);
       std::copy_n(ss, m, &y1[particle_]);
 #ifdef USE_BLAS_AT_FIRST_ORDER
@@ -88,59 +89,60 @@ ss2Iteration_pruning(double *y2, double *y1, const double *yhat2, const double *
           // +ghx·ŷ₂+ghu·ε
 #ifndef USE_BLAS_AT_FIRST_ORDER
           for (int column = 0, column_ = 0; column < n; column++, column_ += m)
-            y2[variable_] += ghx[variable+column_]*yhat2[column+particle__];
+            y2[variable_] += ghx[variable + column_] * yhat2[column + particle__];
           for (int column = 0, column_ = 0; column < q; column++, column_ += m)
-            y2[variable_] += ghu[variable+column_]*epsilon[column+particle___];
+            y2[variable_] += ghu[variable + column_] * epsilon[column + particle___];
 #endif
           // +½ghxx·ŷ₁⊗ŷ₁
-          for (int i = 0; i < n*(n+1)/2; i++)
+          for (int i = 0; i < n * (n + 1) / 2; i++)
             {
-              int i1 = particle__+ii1[i];
-              int i2 = particle__+ii2[i];
+              int i1 = particle__ + ii1[i];
+              int i2 = particle__ + ii2[i];
               if (i1 == i2)
-                y2[variable_] += .5*ghxx[variable+ii3[i]]*yhat1[i1]*yhat1[i1];
+                y2[variable_] += .5 * ghxx[variable + ii3[i]] * yhat1[i1] * yhat1[i1];
               else
-                y2[variable_] += ghxx[variable+ii3[i]]*yhat1[i1]*yhat1[i2];
+                y2[variable_] += ghxx[variable + ii3[i]] * yhat1[i1] * yhat1[i2];
             }
           // +½ghuu·ε⊗ε
-          for (int j = 0; j < q*(q+1)/2; j++)
+          for (int j = 0; j < q * (q + 1) / 2; j++)
             {
-              int j1 = particle___+jj1[j];
-              int j2 = particle___+jj2[j];
+              int j1 = particle___ + jj1[j];
+              int j2 = particle___ + jj2[j];
               if (j1 == j2)
-                y2[variable_] += .5*ghuu[variable+jj3[j]]*epsilon[j1]*epsilon[j1];
+                y2[variable_] += .5 * ghuu[variable + jj3[j]] * epsilon[j1] * epsilon[j1];
               else
-                y2[variable_] += ghuu[variable+jj3[j]]*epsilon[j1]*epsilon[j2];
+                y2[variable_] += ghuu[variable + jj3[j]] * epsilon[j1] * epsilon[j2];
             }
           // +ghxu·ŷ₁⊗ε
-          for (int v = particle__, i = 0; v < particle__+n; v++)
-            for (int s = particle___; s < particle___+q; s++, i += m)
-                y2[variable_] += ghxu[variable+i]*epsilon[s]*yhat1[v];
+          for (int v = particle__, i = 0; v < particle__ + n; v++)
+            for (int s = particle___; s < particle___ + q; s++, i += m)
+              y2[variable_] += ghxu[variable + i] * epsilon[s] * yhat1[v];
 #ifndef USE_BLAS_AT_FIRST_ORDER
           for (int column = 0, column_ = 0; column < q; column++, column_ += m)
             {
-              int i1 = variable+column_;
-              int i2 = column+particle__;
-              int i3 = column+particle___;
-              y1[variable_] += ghx[i1]*yhat1[i2];
-              y1[variable_] += ghu[i1]*epsilon[i3];
+              int i1 = variable + column_;
+              int i2 = column + particle__;
+              int i3 = column + particle___;
+              y1[variable_] += ghx[i1] * yhat1[i2];
+              y1[variable_] += ghu[i1] * epsilon[i3];
             }
-          for (int column = q, column_ = q*m; column < n; column++, column_ += m)
-            y1[variable_] += ghx[variable+column_]*yhat1[column+particle__];
+          for (int column = q, column_ = q * m; column < n; column++, column_ += m)
+            y1[variable_] += ghx[variable + column_] * yhat1[column + particle__];
 #endif
         }
 #ifdef USE_BLAS_AT_FIRST_ORDER
       dgemv("N", &m, &n, &one, &ghx[0], &m, &yhat1[particle__], &ONE, &one, &y1[particle_], &ONE);
-      dgemv("N", &m, &q, &one, &ghu[0], &m, &epsilon[particle___], &ONE, &one, &y1[particle_], &ONE);
+      dgemv("N", &m, &q, &one, &ghu[0], &m, &epsilon[particle___], &ONE, &one, &y1[particle_],
+            &ONE);
 #endif
     }
 }
 
 void
-ss2Iteration(double *y, const double *yhat, const double *epsilon,
-             const double *ghx, const double *ghu,
-             const double *constant, const double *ghxx, const double *ghuu, const double *ghxu,
-             blas_int m, blas_int n, blas_int q, blas_int s, int number_of_threads)
+ss2Iteration(double* y, const double* yhat, const double* epsilon, const double* ghx,
+             const double* ghu, const double* constant, const double* ghxx, const double* ghuu,
+             const double* ghxu, blas_int m, blas_int n, blas_int q, blas_int s,
+             int number_of_threads)
 {
 #ifdef USE_BLAS_AT_FIRST_ORDER
   const double one = 1.0;
@@ -151,9 +153,9 @@ ss2Iteration(double *y, const double *yhat, const double *epsilon,
 #pragma omp parallel for num_threads(number_of_threads)
   for (int particle = 0; particle < s; particle++)
     {
-      int particle_ = particle*m;
-      int particle__ = particle*n;
-      int particle___ = particle*q;
+      int particle_ = particle * m;
+      int particle__ = particle * n;
+      int particle___ = particle * q;
       std::copy_n(constant, m, &y[particle_]);
 #ifdef USE_BLAS_AT_FIRST_ORDER
       dgemv("N", &m, &n, &one, ghx, &m, &yhat[particle__], &ONE, &one, &y[particle_], &ONE);
@@ -165,52 +167,53 @@ ss2Iteration(double *y, const double *yhat, const double *epsilon,
           // +ghx·ŷ+ghu·ε
 #ifndef USE_BLAS_AT_FIRST_ORDER
           for (int column = 0, column_ = 0; column < n; column++, column_ += m)
-            y[variable_] += ghx[variable+column_]*yhat[column+particle__];
+            y[variable_] += ghx[variable + column_] * yhat[column + particle__];
           for (int column = 0, column_ = 0; column < q; column++, column_ += m)
-            y[variable_] += ghu[variable+column_]*epsilon[column+particle___];
+            y[variable_] += ghu[variable + column_] * epsilon[column + particle___];
 #endif
           // +½ghxx·ŷ⊗ŷ
-          for (int i = 0; i < n*(n+1)/2; i++)
+          for (int i = 0; i < n * (n + 1) / 2; i++)
             {
-              int i1 = particle__+ii1[i];
-              int i2 = particle__+ii2[i];
+              int i1 = particle__ + ii1[i];
+              int i2 = particle__ + ii2[i];
               if (i1 == i2)
-                y[variable_] += .5*ghxx[variable+ii3[i]]*yhat[i1]*yhat[i1];
+                y[variable_] += .5 * ghxx[variable + ii3[i]] * yhat[i1] * yhat[i1];
               else
-                y[variable_] += ghxx[variable+ii3[i]]*yhat[i1]*yhat[i2];
+                y[variable_] += ghxx[variable + ii3[i]] * yhat[i1] * yhat[i2];
             }
           // +½ghuu·ε⊗ε
-          for (int j = 0; j < q*(q+1)/2; j++)
+          for (int j = 0; j < q * (q + 1) / 2; j++)
             {
-              int j1 = particle___+jj1[j];
-              int j2 = particle___+jj2[j];
+              int j1 = particle___ + jj1[j];
+              int j2 = particle___ + jj2[j];
               if (j1 == j2)
-                y[variable_] += .5*ghuu[variable+jj3[j]]*epsilon[j1]*epsilon[j1];
+                y[variable_] += .5 * ghuu[variable + jj3[j]] * epsilon[j1] * epsilon[j1];
               else
-                y[variable_] += ghuu[variable+jj3[j]]*epsilon[j1]*epsilon[j2];
+                y[variable_] += ghuu[variable + jj3[j]] * epsilon[j1] * epsilon[j2];
             }
           // +ghxu·ŷ⊗ε
-          for (int v = particle__, i = 0; v < particle__+n; v++)
-            for (int s = particle___; s < particle___+q; s++, i += m)
-              y[variable_] += ghxu[variable+i]*epsilon[s]*yhat[v];
+          for (int v = particle__, i = 0; v < particle__ + n; v++)
+            for (int s = particle___; s < particle___ + q; s++, i += m)
+              y[variable_] += ghxu[variable + i] * epsilon[s] * yhat[v];
         }
     }
 }
 
 void
-mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
+mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
 {
   /*
     prhs[0] yhat          [double]  n×s array, time t particles.
     prhs[1] epsilon       [double]  q×s array, time t innovations.
     prhs[2] ghx           [double]  m×n array, first order reduced form.
     prhs[3] ghu           [double]  m×q array, first order reduced form.
-    prhs[4] constant      [double]  m×1 array, deterministic steady state + second order correction for the union of the states and observed variables.
-    prhs[5] ghxx          [double]  m×n² array, second order reduced form.
-    prhs[6] ghuu          [double]  m×q² array, second order reduced form.
-    prhs[7] ghxu          [double]  m×nq array, second order reduced form.
-    prhs[8] yhat_         [double]  [OPTIONAL] n×s array, time t particles (pruning additional latent variables).
-    prhs[9] ss            [double]  [OPTIONAL] m×1 array, steady state for the union of the states and the observed variables (needed for the pruning mode).
+    prhs[4] constant      [double]  m×1 array, deterministic steady state + second order correction
+    for the union of the states and observed variables. prhs[5] ghxx          [double]  m×n² array,
+    second order reduced form. prhs[6] ghuu          [double]  m×q² array, second order reduced
+    form. prhs[7] ghxu          [double]  m×nq array, second order reduced form. prhs[8] yhat_
+    [double]  [OPTIONAL] n×s array, time t particles (pruning additional latent variables). prhs[9]
+    ss            [double]  [OPTIONAL] m×1 array, steady state for the union of the states and the
+    observed variables (needed for the pruning mode).
 
     prhs[8 or 10]         [double]  num of threads
 
@@ -225,10 +228,10 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
   if (nlhs > 2)
     mexErrMsgTxt("Too many output arguments.");
 
-  auto check_input_real_dense_array = [=](int i)
-  {
+  auto check_input_real_dense_array = [=](int i) {
     if (!mxIsDouble(prhs[i]) || mxIsComplex(prhs[i]) || mxIsSparse(prhs[i]))
-      mexErrMsgTxt(("Input argument " + std::to_string(i+1) + " should be a real dense array").c_str());
+      mexErrMsgTxt(
+          ("Input argument " + std::to_string(i + 1) + " should be a real dense array").c_str());
   };
 
   for (int i = 0; i < 8; i++)
@@ -240,38 +243,39 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
   size_t q = mxGetM(prhs[1]); // Number of innovations.
   size_t m = mxGetM(prhs[2]); // Number of elements in the union of states and observed variables.
   // Check the dimensions.
-  if (s != mxGetN(prhs[1]) // Number of columns for epsilon
+  if (s != mxGetN(prhs[1])    // Number of columns for epsilon
       || n != mxGetN(prhs[2]) // Number of columns for ghx
       || m != mxGetM(prhs[3]) // Number of rows for ghu
       || q != mxGetN(prhs[3]) // Number of columns for ghu
-      || m != mxGetM(prhs[4]) // Number of rows for 2nd order constant correction + deterministic steady state
+      || m != mxGetM(prhs[4]) // Number of rows for 2nd order constant correction + deterministic
+                              // steady state
       || m != mxGetM(prhs[5]) // Number of rows for ghxx
-      || n*n != mxGetN(prhs[5]) // Number of columns for ghxx
-      || m != mxGetM(prhs[6]) // Number of rows for ghuu
-      || q*q != mxGetN(prhs[6]) // Number of columns for ghuu
-      || m != mxGetM(prhs[7]) // Number of rows for ghxu
-      || n*q != mxGetN(prhs[7])) // Number of rows for ghxu
+      || n * n != mxGetN(prhs[5])  // Number of columns for ghxx
+      || m != mxGetM(prhs[6])      // Number of rows for ghuu
+      || q * q != mxGetN(prhs[6])  // Number of columns for ghuu
+      || m != mxGetM(prhs[7])      // Number of rows for ghxu
+      || n * q != mxGetN(prhs[7])) // Number of rows for ghxu
     mexErrMsgTxt("Input dimension mismatch!.");
   if (nrhs > 9)
     {
       for (int i = 8; i < 10; i++)
         check_input_real_dense_array(i);
 
-      if (n != mxGetM(prhs[8]) // Number of rows for yhat_
-          || s != mxGetN(prhs[8]) // Number of columns for yhat_
+      if (n != mxGetM(prhs[8])     // Number of rows for yhat_
+          || s != mxGetN(prhs[8])  // Number of columns for yhat_
           || m != mxGetM(prhs[9])) // Number of rows for ss
         mexErrMsgTxt("Input dimension mismatch!.");
     }
 
   // Get Input arrays.
-  const double *yhat = mxGetPr(prhs[0]);
-  const double *epsilon = mxGetPr(prhs[1]);
-  const double *ghx = mxGetPr(prhs[2]);
-  const double *ghu = mxGetPr(prhs[3]);
-  const double *constant = mxGetPr(prhs[4]);
-  const double *ghxx = mxGetPr(prhs[5]);
-  const double *ghuu = mxGetPr(prhs[6]);
-  const double *ghxu = mxGetPr(prhs[7]);
+  const double* yhat = mxGetPr(prhs[0]);
+  const double* epsilon = mxGetPr(prhs[1]);
+  const double* ghx = mxGetPr(prhs[2]);
+  const double* ghu = mxGetPr(prhs[3]);
+  const double* constant = mxGetPr(prhs[4]);
+  const double* ghxx = mxGetPr(prhs[5]);
+  const double* ghuu = mxGetPr(prhs[6]);
+  const double* ghxu = mxGetPr(prhs[7]);
   const double *yhat_ = nullptr, *ss = nullptr;
   if (nrhs > 9)
     {
@@ -279,7 +283,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
       ss = mxGetPr(prhs[9]);
     }
 
-  const mxArray *numthreads_mx = prhs[nrhs == 9 ? 8 : 10];
+  const mxArray* numthreads_mx = prhs[nrhs == 9 ? 8 : 10];
   if (!(mxIsScalar(numthreads_mx) && mxIsNumeric(numthreads_mx)))
     mexErrMsgTxt("Last argument should be a numeric scalar");
   int numthreads = static_cast<int>(mxGetScalar(numthreads_mx));
@@ -293,15 +297,18 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
   if (nrhs == 9)
     {
       plhs[0] = mxCreateDoubleMatrix(m, s, mxREAL);
-      double *y = mxGetPr(plhs[0]);
-      ss2Iteration(y, yhat, epsilon, ghx, ghu, constant, ghxx, ghuu, ghxu, static_cast<int>(m), static_cast<int>(n), static_cast<int>(q), static_cast<int>(s), numthreads);
+      double* y = mxGetPr(plhs[0]);
+      ss2Iteration(y, yhat, epsilon, ghx, ghu, constant, ghxx, ghuu, ghxu, static_cast<int>(m),
+                   static_cast<int>(n), static_cast<int>(q), static_cast<int>(s), numthreads);
     }
   else
     {
       plhs[0] = mxCreateDoubleMatrix(m, s, mxREAL);
       plhs[1] = mxCreateDoubleMatrix(m, s, mxREAL);
-      double *y = mxGetPr(plhs[0]);
-      double *y_ = mxGetPr(plhs[1]);
-      ss2Iteration_pruning(y, y_, yhat, yhat_, epsilon, ghx, ghu, constant, ghxx, ghuu, ghxu, ss, static_cast<int>(m), static_cast<int>(n), static_cast<int>(q), static_cast<int>(s), numthreads);
+      double* y = mxGetPr(plhs[0]);
+      double* y_ = mxGetPr(plhs[1]);
+      ss2Iteration_pruning(y, y_, yhat, yhat_, epsilon, ghx, ghu, constant, ghxx, ghuu, ghxu, ss,
+                           static_cast<int>(m), static_cast<int>(n), static_cast<int>(q),
+                           static_cast<int>(s), numthreads);
     }
 }
diff --git a/mex/sources/ms-sbvar/mex_top_level.cc b/mex/sources/ms-sbvar/mex_top_level.cc
index d994a37ee2c44e4e91b3f9fcf81ed91cd9c6d29f..79432b8f08e823c4b9fc55fab0260e03707b0416 100644
--- a/mex/sources/ms-sbvar/mex_top_level.cc
+++ b/mex/sources/ms-sbvar/mex_top_level.cc
@@ -17,52 +17,52 @@
  * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
  */
 
+#include <cctype>
 #include <cstdlib>
 #include <cstring>
-#include <cctype>
 #include <dynmex.h>
 
 #include "modify_for_mex.h"
 
-int main(int nargs, char **args);
+int main(int nargs, char** args);
 
 void
-mexFunction(int nlhs, [[maybe_unused]] mxArray *plhs[],
-            int nrhs, const mxArray *prhs[])
+mexFunction(int nlhs, [[maybe_unused]] mxArray* plhs[], int nrhs, const mxArray* prhs[])
 {
   int nargs = 0;
-  const char *mainarg = "./a.out";
+  const char* mainarg = "./a.out";
 
   /*
    * Check args
    */
   if (nrhs != 1 || !mxIsChar(prhs[0]) || nlhs != 0)
-    mexErrMsgTxt("Error in MS-SBVAR MEX file: this function takes 1 string input argument and returns no output argument.");
+    mexErrMsgTxt("Error in MS-SBVAR MEX file: this function takes 1 string input argument and "
+                 "returns no output argument.");
 
   /*
    * Allocate memory
    */
-  int maxnargs = static_cast<int>(mxGetN(prhs[0])/2+1);
-  char *argument = static_cast<char *>(mxCalloc(mxGetN(prhs[0])+1, sizeof(char)));
-  char **args = static_cast<char **>(mxCalloc(maxnargs, sizeof(char *)));
+  int maxnargs = static_cast<int>(mxGetN(prhs[0]) / 2 + 1);
+  char* argument = static_cast<char*>(mxCalloc(mxGetN(prhs[0]) + 1, sizeof(char)));
+  char** args = static_cast<char**>(mxCalloc(maxnargs, sizeof(char*)));
   if (!argument || !args)
     mexErrMsgTxt("Error in MS-SBVAR MEX file: could not allocate memory. (1)");
 
   /*
    * Create argument string from prhs and parse to create args / nargs
    */
-  if (!(args[nargs] = static_cast<char *>(mxCalloc(strlen(mainarg)+1, sizeof(char)))))
+  if (!(args[nargs] = static_cast<char*>(mxCalloc(strlen(mainarg) + 1, sizeof(char)))))
     mexErrMsgTxt("Error in MS-SBVAR MEX file: could not allocate memory. (2)");
 
   strcpy(args[nargs++], mainarg);
 
-  if (mxGetString(prhs[0], argument, mxGetN(prhs[0])+1))
+  if (mxGetString(prhs[0], argument, mxGetN(prhs[0]) + 1))
     mexErrMsgTxt("Error in MS-SBVAR MEX file: error using mxGetString.\n");
 
-  char *beginarg = argument;
+  char* beginarg = argument;
   while (int n = strcspn(beginarg, " "))
     {
-      if (!(args[nargs] = static_cast<char *>(mxCalloc(n+1, sizeof(char)))))
+      if (!(args[nargs] = static_cast<char*>(mxCalloc(n + 1, sizeof(char)))))
         mexErrMsgTxt("Error in MS-SBVAR MEX file: could not allocate memory. (3)");
 
       strncpy(args[nargs++], beginarg, n);
@@ -77,7 +77,7 @@ mexFunction(int nlhs, [[maybe_unused]] mxArray *plhs[],
     {
       main(nargs, args);
     }
-  catch (const char *str)
+  catch (const char* str)
     {
       mexErrMsgTxt(str);
     }
diff --git a/mex/sources/ms-sbvar/modify_for_mex.cc b/mex/sources/ms-sbvar/modify_for_mex.cc
index 52206e073527dc46d6ab749cc7400c076749bd04..ad7fd75827e59d5058a4d06eddae70442d56798a 100644
--- a/mex/sources/ms-sbvar/modify_for_mex.cc
+++ b/mex/sources/ms-sbvar/modify_for_mex.cc
@@ -19,9 +19,7 @@
 
 #include <dynmex.h>
 
-extern "C"
-[[noreturn]]
-void
+extern "C" [[noreturn]] void
 msExit([[maybe_unused]] int status)
 {
   throw "Error in MS-SBVAR MEX file.\n";
diff --git a/mex/sources/ms-sbvar/modify_for_mex.h b/mex/sources/ms-sbvar/modify_for_mex.h
index 3fcb78b4d2384362521ff98e04bd826f0ec4534e..27f18432b6b3c7451d97b372ba3c07570a31b13a 100644
--- a/mex/sources/ms-sbvar/modify_for_mex.h
+++ b/mex/sources/ms-sbvar/modify_for_mex.h
@@ -20,9 +20,9 @@
 #ifndef _MODIFY_FOR_MEX_H
 #define _MODIFY_FOR_MEX_H
 
-#include <dynmex.h>
 #include <dynblas.h>
 #include <dynlapack.h>
+#include <dynmex.h>
 
 #define dw_malloc mxMalloc
 #define dw_calloc mxCalloc
@@ -37,7 +37,8 @@ extern "C"
 # else
 extern
 # endif
-bool utIsInterruptPending();
+    bool
+    utIsInterruptPending();
 #else
 # include <octave/quit.h>
 #endif
@@ -48,10 +49,11 @@ extern "C"
 // NB: C23 has the [[noreturn]] attribute, so this #ifdef can be removed when
 // we upgrade
 #ifdef __cplusplus
-[[noreturn]]
+    [[noreturn]]
 #else
 _Noreturn
 #endif
-void msExit(int status);
+    void
+    msExit(int status);
 
 #endif // _MODIFY_FOR_MEX_H
diff --git a/mex/sources/num_procs/num_procs.cc b/mex/sources/num_procs/num_procs.cc
index 15b99a68618466996676dbd43419a43906a3dc52..4193b99557eb3fccbb6b21e7bd58a85b103bbb06 100644
--- a/mex/sources/num_procs/num_procs.cc
+++ b/mex/sources/num_procs/num_procs.cc
@@ -22,8 +22,7 @@
 #include <dynmex.h>
 
 void
-mexFunction(int nlhs, mxArray *plhs[],
-            int nrhs, [[maybe_unused]] const mxArray *prhs[])
+mexFunction(int nlhs, mxArray* plhs[], int nrhs, [[maybe_unused]] const mxArray* prhs[])
 {
   if (nrhs != 0 || nlhs != 1)
     mexErrMsgTxt("Must have zero input argument and one output argument");
diff --git a/mex/sources/perfect_foresight_problem/DynamicModelCaller.cc b/mex/sources/perfect_foresight_problem/DynamicModelCaller.cc
index a366932fcb0f6810c546c8582018ea3ddcb4cee0..283c93321079070fa0c3fdd4ca57025b65fac1d3 100644
--- a/mex/sources/perfect_foresight_problem/DynamicModelCaller.cc
+++ b/mex/sources/perfect_foresight_problem/DynamicModelCaller.cc
@@ -29,22 +29,24 @@ using namespace std::literals::string_literals;
 std::string DynamicModelCaller::error_msg;
 
 #if !defined(_WIN32) && !defined(__CYGWIN32__)
-void *DynamicModelDllCaller::resid_mex{nullptr};
-void *DynamicModelDllCaller::g1_mex{nullptr};
+void* DynamicModelDllCaller::resid_mex {nullptr};
+void* DynamicModelDllCaller::g1_mex {nullptr};
 #else
-HINSTANCE DynamicModelDllCaller::resid_mex{nullptr};
-HINSTANCE DynamicModelDllCaller::g1_mex{nullptr};
+HINSTANCE DynamicModelDllCaller::resid_mex {nullptr};
+HINSTANCE DynamicModelDllCaller::g1_mex {nullptr};
 #endif
-DynamicModelDllCaller::dynamic_tt_fct DynamicModelDllCaller::residual_tt_fct{nullptr}, DynamicModelDllCaller::g1_tt_fct{nullptr};
-DynamicModelDllCaller::dynamic_fct DynamicModelDllCaller::residual_fct{nullptr}, DynamicModelDllCaller::g1_fct{nullptr};
+DynamicModelDllCaller::dynamic_tt_fct DynamicModelDllCaller::residual_tt_fct {nullptr},
+    DynamicModelDllCaller::g1_tt_fct {nullptr};
+DynamicModelDllCaller::dynamic_fct DynamicModelDllCaller::residual_fct {nullptr},
+    DynamicModelDllCaller::g1_fct {nullptr};
 
 void
-DynamicModelDllCaller::load_dll(const std::string &basename)
+DynamicModelDllCaller::load_dll(const std::string& basename)
 {
   // Load symbols from dynamic MEX
   const std::filesystem::path sparse_dir {"+" + basename + "/+sparse/"};
   const std::filesystem::path resid_mex_name {sparse_dir / ("dynamic_resid"s + MEXEXT)},
-    g1_mex_name {sparse_dir / ("dynamic_g1"s + MEXEXT)};
+      g1_mex_name {sparse_dir / ("dynamic_g1"s + MEXEXT)};
 #if !defined(__CYGWIN32__) && !defined(_WIN32)
   resid_mex = dlopen(resid_mex_name.c_str(), RTLD_NOW);
   g1_mex = dlopen(g1_mex_name.c_str(), RTLD_NOW);
@@ -87,27 +89,30 @@ DynamicModelDllCaller::unload_dll()
 #endif
 }
 
-DynamicModelDllCaller::DynamicModelDllCaller(size_t ntt, mwIndex ny, mwIndex nx, const double *params_arg, const double *steady_state_arg, const int32_T *g1_sparse_colptr_arg, bool linear_arg, bool compute_jacobian_arg) :
-  DynamicModelCaller{linear_arg, compute_jacobian_arg},
-  params{params_arg}, steady_state{steady_state_arg},
-  g1_sparse_colptr{g1_sparse_colptr_arg}
+DynamicModelDllCaller::DynamicModelDllCaller(size_t ntt, mwIndex ny, mwIndex nx,
+                                             const double* params_arg,
+                                             const double* steady_state_arg,
+                                             const int32_T* g1_sparse_colptr_arg, bool linear_arg,
+                                             bool compute_jacobian_arg) :
+    DynamicModelCaller {linear_arg, compute_jacobian_arg},
+    params {params_arg}, steady_state {steady_state_arg}, g1_sparse_colptr {g1_sparse_colptr_arg}
 {
   tt = std::make_unique<double[]>(ntt);
-  y_p = std::make_unique<double[]>(3*ny);
+  y_p = std::make_unique<double[]>(3 * ny);
   x_p = std::make_unique<double[]>(nx);
   if (compute_jacobian)
-    jacobian_p = std::make_unique<double[]>(g1_sparse_colptr[3*ny+nx]-1);
+    jacobian_p = std::make_unique<double[]>(g1_sparse_colptr[3 * ny + nx] - 1);
 }
 
 void
-DynamicModelDllCaller::copy_jacobian_column(mwIndex col, double *dest) const
+DynamicModelDllCaller::copy_jacobian_column(mwIndex col, double* dest) const
 {
-  std::copy_n(jacobian_p.get() + g1_sparse_colptr[col]-1,
-              g1_sparse_colptr[col+1] - g1_sparse_colptr[col], dest);
+  std::copy_n(jacobian_p.get() + g1_sparse_colptr[col] - 1,
+              g1_sparse_colptr[col + 1] - g1_sparse_colptr[col], dest);
 }
 
 void
-DynamicModelDllCaller::eval(double *resid)
+DynamicModelDllCaller::eval(double* resid)
 {
   residual_tt_fct(y_p.get(), x_p.get(), params, steady_state, tt.get());
   residual_fct(y_p.get(), x_p.get(), params, steady_state, tt.get(), resid);
@@ -121,17 +126,21 @@ DynamicModelDllCaller::eval(double *resid)
     }
 }
 
-DynamicModelMatlabCaller::DynamicModelMatlabCaller(std::string basename_arg, mwIndex ny, mwIndex nx, const mxArray *params_mx_arg, const mxArray *steady_state_mx_arg, const mxArray *g1_sparse_rowval_mx_arg, const mxArray *g1_sparse_colval_mx_arg, const mxArray *g1_sparse_colptr_mx_arg, bool linear_arg, bool compute_jacobian_arg) :
-  DynamicModelCaller{linear_arg, compute_jacobian_arg},
-  basename{std::move(basename_arg)},
-  y_mx{mxCreateDoubleMatrix(3*ny, 1, mxREAL)},
-  x_mx{mxCreateDoubleMatrix(nx, 1, mxREAL)},
-  jacobian_mx{nullptr},
-  params_mx{mxDuplicateArray(params_mx_arg)},
-  steady_state_mx{mxDuplicateArray(steady_state_mx_arg)},
-  g1_sparse_rowval_mx{mxDuplicateArray(g1_sparse_rowval_mx_arg)},
-  g1_sparse_colval_mx{mxDuplicateArray(g1_sparse_colval_mx_arg)},
-  g1_sparse_colptr_mx{mxDuplicateArray(g1_sparse_colptr_mx_arg)}
+DynamicModelMatlabCaller::DynamicModelMatlabCaller(std::string basename_arg, mwIndex ny, mwIndex nx,
+                                                   const mxArray* params_mx_arg,
+                                                   const mxArray* steady_state_mx_arg,
+                                                   const mxArray* g1_sparse_rowval_mx_arg,
+                                                   const mxArray* g1_sparse_colval_mx_arg,
+                                                   const mxArray* g1_sparse_colptr_mx_arg,
+                                                   bool linear_arg, bool compute_jacobian_arg) :
+    DynamicModelCaller {linear_arg, compute_jacobian_arg},
+    basename {std::move(basename_arg)}, y_mx {mxCreateDoubleMatrix(3 * ny, 1, mxREAL)},
+    x_mx {mxCreateDoubleMatrix(nx, 1, mxREAL)}, jacobian_mx {nullptr}, params_mx {mxDuplicateArray(
+                                                                           params_mx_arg)},
+    steady_state_mx {mxDuplicateArray(steady_state_mx_arg)}, g1_sparse_rowval_mx {mxDuplicateArray(
+                                                                 g1_sparse_rowval_mx_arg)},
+    g1_sparse_colval_mx {mxDuplicateArray(g1_sparse_colval_mx_arg)},
+    g1_sparse_colptr_mx {mxDuplicateArray(g1_sparse_colptr_mx_arg)}
 {
 }
 
@@ -149,16 +158,16 @@ DynamicModelMatlabCaller::~DynamicModelMatlabCaller()
 }
 
 void
-DynamicModelMatlabCaller::copy_jacobian_column(mwIndex col, double *dest) const
+DynamicModelMatlabCaller::copy_jacobian_column(mwIndex col, double* dest) const
 {
   if (jacobian_mx)
     {
 #if MX_HAS_INTERLEAVED_COMPLEX
-      const int32_T *g1_sparse_rowval {mxGetInt32s(g1_sparse_rowval_mx)};
-      const int32_T *g1_sparse_colptr {mxGetInt32s(g1_sparse_colptr_mx)};
+      const int32_T* g1_sparse_rowval {mxGetInt32s(g1_sparse_rowval_mx)};
+      const int32_T* g1_sparse_colptr {mxGetInt32s(g1_sparse_colptr_mx)};
 #else
-      const int32_T *g1_sparse_rowval {static_cast<const int32_T *>(mxGetData(g1_sparse_rowval_mx))};
-      const int32_T *g1_sparse_colptr {static_cast<const int32_T *>(mxGetData(g1_sparse_colptr_mx))};
+      const int32_T* g1_sparse_rowval {static_cast<const int32_T*>(mxGetData(g1_sparse_rowval_mx))};
+      const int32_T* g1_sparse_colptr {static_cast<const int32_T*>(mxGetData(g1_sparse_colptr_mx))};
 #endif
 
       /* We cannot assume that jacobian_mx internally uses
@@ -169,12 +178,13 @@ DynamicModelMatlabCaller::copy_jacobian_column(mwIndex col, double *dest) const
       mwIndex *ir {mxGetIr(jacobian_mx)}, *jc {mxGetJc(jacobian_mx)};
       mwIndex isrc {jc[col]}; // Index in value array of source Jacobian
       for (mwIndex idest {0}; // Index in value array of destination Jacobian
-           idest < static_cast<mwIndex>(g1_sparse_colptr[col+1]-g1_sparse_colptr[col]); idest++)
+           idest < static_cast<mwIndex>(g1_sparse_colptr[col + 1] - g1_sparse_colptr[col]); idest++)
         {
-          mwIndex row {static_cast<mwIndex>(g1_sparse_rowval[idest+g1_sparse_colptr[col]-1]-1)};
-          while (isrc < jc[col+1] && ir[isrc] < row)
+          mwIndex row {
+              static_cast<mwIndex>(g1_sparse_rowval[idest + g1_sparse_colptr[col] - 1] - 1)};
+          while (isrc < jc[col + 1] && ir[isrc] < row)
             isrc++;
-          if (isrc < jc[col+1] && ir[isrc] == row)
+          if (isrc < jc[col + 1] && ir[isrc] == row)
             dest[idest] = mxGetPr(jacobian_mx)[isrc];
           else
             dest[idest] = 0.0;
@@ -183,16 +193,18 @@ DynamicModelMatlabCaller::copy_jacobian_column(mwIndex col, double *dest) const
 }
 
 void
-DynamicModelMatlabCaller::eval(double *resid)
+DynamicModelMatlabCaller::eval(double* resid)
 {
   mxArray *T_order_mx, *T_mx;
 
   {
     // Compute residuals
     std::string funcname {basename + ".sparse.dynamic_resid"};
-    mxArray *plhs[3], *prhs[] = { y_mx, x_mx, params_mx, steady_state_mx };
+    mxArray *plhs[3], *prhs[] = {y_mx, x_mx, params_mx, steady_state_mx};
 
-    mxArray *exception { mexCallMATLABWithTrap(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>, prhs, funcname.c_str()) };
+    mxArray* exception {mexCallMATLABWithTrap(std::extent_v<decltype(plhs)>, plhs,
+                                              std::extent_v<decltype(prhs)>, prhs,
+                                              funcname.c_str())};
     if (exception)
       {
         error_msg = "An error occurred when calling " + funcname;
@@ -219,9 +231,19 @@ DynamicModelMatlabCaller::eval(double *resid)
     {
       // Compute Jacobian
       std::string funcname {basename + ".sparse.dynamic_g1"};
-      mxArray *plhs[1], *prhs[] = { y_mx, x_mx, params_mx, steady_state_mx, g1_sparse_rowval_mx, g1_sparse_colval_mx, g1_sparse_colptr_mx, T_order_mx, T_mx };
+      mxArray *plhs[1], *prhs[] = {y_mx,
+                                   x_mx,
+                                   params_mx,
+                                   steady_state_mx,
+                                   g1_sparse_rowval_mx,
+                                   g1_sparse_colval_mx,
+                                   g1_sparse_colptr_mx,
+                                   T_order_mx,
+                                   T_mx};
 
-      mxArray *exception { mexCallMATLABWithTrap(std::extent_v<decltype(plhs)>, plhs, std::extent_v<decltype(prhs)>, prhs, funcname.c_str()) };
+      mxArray* exception {mexCallMATLABWithTrap(std::extent_v<decltype(plhs)>, plhs,
+                                                std::extent_v<decltype(prhs)>, prhs,
+                                                funcname.c_str())};
       if (exception)
         {
           error_msg = "An error occurred when calling " + funcname;
diff --git a/mex/sources/perfect_foresight_problem/DynamicModelCaller.hh b/mex/sources/perfect_foresight_problem/DynamicModelCaller.hh
index 9bbc7246e82c31b4951c53a1840cc9457cb3d578..e09a00441a281c67d53acbc4742f9fb50f6e8eff 100644
--- a/mex/sources/perfect_foresight_problem/DynamicModelCaller.hh
+++ b/mex/sources/perfect_foresight_problem/DynamicModelCaller.hh
@@ -17,11 +17,11 @@
  * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#include <string>
-#include <memory>
+#include <algorithm>
 #include <limits>
+#include <memory>
+#include <string>
 #include <type_traits>
-#include <algorithm>
 
 #if defined(_WIN32) || defined(__CYGWIN32__)
 # ifndef NOMINMAX
@@ -36,21 +36,23 @@ class DynamicModelCaller
 {
 public:
   const bool linear;
-  bool compute_jacobian; // Not constant, because will be changed from true to false for linear models after first evaluation
+  bool compute_jacobian; // Not constant, because will be changed from true to false for linear
+                         // models after first evaluation
 
   // Used to store error messages (as exceptions cannot cross the OpenMP boundary)
   static std::string error_msg;
 
-  DynamicModelCaller(bool linear_arg, bool compute_jacobian_arg) : linear{linear_arg}, compute_jacobian{compute_jacobian_arg}
+  DynamicModelCaller(bool linear_arg, bool compute_jacobian_arg) :
+      linear {linear_arg}, compute_jacobian {compute_jacobian_arg}
   {
   }
   virtual ~DynamicModelCaller() = default;
-  virtual double *y() const = 0;
-  virtual double *x() const = 0;
+  virtual double* y() const = 0;
+  virtual double* x() const = 0;
   /* Copy a column of the Jacobian to dest.
      Only copies non-zero elements, according to g1_sparse_{rowval,colval,colptr}. */
-  virtual void copy_jacobian_column(mwIndex col, double *dest) const = 0;
-  virtual void eval(double *resid) = 0;
+  virtual void copy_jacobian_column(mwIndex col, double* dest) const = 0;
+  virtual void eval(double* resid) = 0;
 };
 
 class DynamicModelDllCaller : public DynamicModelCaller
@@ -61,30 +63,34 @@ private:
 #else
   static void *resid_mex, *g1_mex;
 #endif
-  using dynamic_tt_fct = void (*)(const double *y, const double *x, const double *params, const double *steady_state, double *T);
-  using dynamic_fct = void (*)(const double *y, const double *x, const double *params, const double *steady_state, const double *T, double *value);
+  using dynamic_tt_fct = void (*)(const double* y, const double* x, const double* params,
+                                  const double* steady_state, double* T);
+  using dynamic_fct = void (*)(const double* y, const double* x, const double* params,
+                               const double* steady_state, const double* T, double* value);
   static dynamic_tt_fct residual_tt_fct, g1_tt_fct;
   static dynamic_fct residual_fct, g1_fct;
   const double *params, *steady_state;
   std::unique_ptr<double[]> tt, y_p, x_p, jacobian_p;
-  const int32_T *g1_sparse_colptr;
+  const int32_T* g1_sparse_colptr;
 
 public:
-  DynamicModelDllCaller(size_t ntt, mwIndex ny, mwIndex nx, const double *params_arg, const double *steady_state_arg, const int32_T *g1_sparse_colptr_arg, bool linear_arg, bool compute_jacobian_arg);
+  DynamicModelDllCaller(size_t ntt, mwIndex ny, mwIndex nx, const double* params_arg,
+                        const double* steady_state_arg, const int32_T* g1_sparse_colptr_arg,
+                        bool linear_arg, bool compute_jacobian_arg);
   virtual ~DynamicModelDllCaller() = default;
-  double *
+  double*
   y() const override
   {
     return y_p.get();
   }
-  double *
+  double*
   x() const override
   {
     return x_p.get();
   }
-  void copy_jacobian_column(mwIndex col, double *dest) const override;
-  void eval(double *resid) override;
-  static void load_dll(const std::string &basename);
+  void copy_jacobian_column(mwIndex col, double* dest) const override;
+  void eval(double* resid) override;
+  static void load_dll(const std::string& basename);
   static void unload_dll();
 };
 
@@ -92,7 +98,8 @@ class DynamicModelMatlabCaller : public DynamicModelCaller
 {
 private:
   std::string basename;
-  mxArray *y_mx, *x_mx, *jacobian_mx, *params_mx, *steady_state_mx, *g1_sparse_rowval_mx, *g1_sparse_colval_mx, *g1_sparse_colptr_mx;
+  mxArray *y_mx, *x_mx, *jacobian_mx, *params_mx, *steady_state_mx, *g1_sparse_rowval_mx,
+      *g1_sparse_colval_mx, *g1_sparse_colptr_mx;
   /* Given a complex matrix (of double floats), returns a sparse matrix of same size.
      Real elements of the original matrix are copied as-is to the new one.
      Complex elements are replaced by NaNs.
@@ -100,55 +107,68 @@ private:
      There are two versions, one for dense matrices, another for sparse
      matrices. */
   template<bool sparse>
-  static mxArray *cmplxToReal(mxArray *cmplx_mx);
+  static mxArray* cmplxToReal(mxArray* cmplx_mx);
+
 public:
-  DynamicModelMatlabCaller(std::string basename_arg, mwIndex ny, mwIndex nx, const mxArray *params_mx_arg, const mxArray *steady_state_mx_arg, const mxArray *g1_sparse_rowval_mx_arg, const mxArray *g1_sparse_colval_mx_arg, const mxArray *g1_sparse_colptr_mx_arg, bool linear_arg, bool compute_jacobian_arg);
+  DynamicModelMatlabCaller(std::string basename_arg, mwIndex ny, mwIndex nx,
+                           const mxArray* params_mx_arg, const mxArray* steady_state_mx_arg,
+                           const mxArray* g1_sparse_rowval_mx_arg,
+                           const mxArray* g1_sparse_colval_mx_arg,
+                           const mxArray* g1_sparse_colptr_mx_arg, bool linear_arg,
+                           bool compute_jacobian_arg);
   ~DynamicModelMatlabCaller() override;
-  double *
+  double*
   y() const override
   {
     return mxGetPr(y_mx);
   }
-  double *
+  double*
   x() const override
   {
     return mxGetPr(x_mx);
   }
-  void copy_jacobian_column(mwIndex col, double *dest) const override;
-  void eval(double *resid) override;
+  void copy_jacobian_column(mwIndex col, double* dest) const override;
+  void eval(double* resid) override;
   class Exception
   {
   public:
     const std::string msg;
-    Exception(std::string msg_arg) : msg{std::move(msg_arg)}
+    Exception(std::string msg_arg) : msg {std::move(msg_arg)}
     {
     }
   };
 };
 
 template<bool sparse>
-mxArray *
-DynamicModelMatlabCaller::cmplxToReal(mxArray *cmplx_mx)
+mxArray*
+DynamicModelMatlabCaller::cmplxToReal(mxArray* cmplx_mx)
 {
-  mxArray *real_mx {sparse ?
-      mxCreateSparse(mxGetM(cmplx_mx), mxGetN(cmplx_mx), mxGetNzmax(cmplx_mx), mxREAL) :
-      mxCreateDoubleMatrix(mxGetM(cmplx_mx), mxGetN(cmplx_mx), mxREAL)};
+  mxArray* real_mx {
+      sparse ? mxCreateSparse(mxGetM(cmplx_mx), mxGetN(cmplx_mx), mxGetNzmax(cmplx_mx), mxREAL)
+             : mxCreateDoubleMatrix(mxGetM(cmplx_mx), mxGetN(cmplx_mx), mxREAL)};
 
-  if constexpr(sparse)
+  if constexpr (sparse)
     {
       std::copy_n(mxGetIr(cmplx_mx), mxGetNzmax(cmplx_mx), mxGetIr(real_mx));
-      std::copy_n(mxGetJc(cmplx_mx), mxGetN(cmplx_mx)+1, mxGetJc(real_mx));
+      std::copy_n(mxGetJc(cmplx_mx), mxGetN(cmplx_mx) + 1, mxGetJc(real_mx));
     }
 
 #if MX_HAS_INTERLEAVED_COMPLEX
-  mxComplexDouble *cmplx {mxGetComplexDoubles(cmplx_mx)};
+  mxComplexDouble* cmplx {mxGetComplexDoubles(cmplx_mx)};
 #else
-  double *cmplx_real {mxGetPr(cmplx_mx)};
-  double *cmplx_imag {mxGetPi(cmplx_mx)};
+  double* cmplx_real {mxGetPr(cmplx_mx)};
+  double* cmplx_imag {mxGetPi(cmplx_mx)};
 #endif
-  double *real {mxGetPr(real_mx)};
+  double* real {mxGetPr(real_mx)};
   for (std::conditional_t<sparse, mwSize, size_t> i {0};
-       i < [&]{ if constexpr(sparse) return mxGetNzmax(cmplx_mx); else return mxGetNumberOfElements(cmplx_mx); }(); // Use a lambda instead of the ternary operator to have the right type (there is no constexpr ternary operator)
+       i <
+       [&] {
+         if constexpr (sparse)
+           return mxGetNzmax(cmplx_mx);
+         else
+           return mxGetNumberOfElements(cmplx_mx);
+       }(); // Use a lambda instead of the ternary operator to have the right type (there is no
+            // constexpr ternary operator)
        i++)
 #if MX_HAS_INTERLEAVED_COMPLEX
     if (cmplx[i].imag == 0.0)
diff --git a/mex/sources/perfect_foresight_problem/perfect_foresight_problem.cc b/mex/sources/perfect_foresight_problem/perfect_foresight_problem.cc
index bcad9f6cd30717c11dacbef1d0e631cc2fbb9513..8c60eb7d6239878db15f637b15d1a40dd09ad88e 100644
--- a/mex/sources/perfect_foresight_problem/perfect_foresight_problem.cc
+++ b/mex/sources/perfect_foresight_problem/perfect_foresight_problem.cc
@@ -17,75 +17,76 @@
  * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#include <string>
-#include <memory>
 #include <algorithm>
+#include <memory>
+#include <string>
 
 #include <dynmex.h>
 
 #include "DynamicModelCaller.hh"
 
 void
-mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
+mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
 {
   if (nlhs < 1 || nlhs > 2 || nrhs != 9)
     mexErrMsgTxt("Must have 9 input arguments and 1 or 2 output arguments");
   bool compute_jacobian = nlhs == 2;
 
   // Give explicit names to input arguments
-  const mxArray *y_mx = prhs[0];
-  const mxArray *y0_mx = prhs[1];
-  const mxArray *yT_mx = prhs[2];
-  const mxArray *exo_path_mx = prhs[3];
-  const mxArray *params_mx = prhs[4];
-  const mxArray *steady_state_mx = prhs[5];
-  const mxArray *periods_mx = prhs[6];
-  const mxArray *M_mx = prhs[7];
-  const mxArray *options_mx = prhs[8];
+  const mxArray* y_mx = prhs[0];
+  const mxArray* y0_mx = prhs[1];
+  const mxArray* yT_mx = prhs[2];
+  const mxArray* exo_path_mx = prhs[3];
+  const mxArray* params_mx = prhs[4];
+  const mxArray* steady_state_mx = prhs[5];
+  const mxArray* periods_mx = prhs[6];
+  const mxArray* M_mx = prhs[7];
+  const mxArray* options_mx = prhs[8];
 
   // Extract various fields from M_
-  const mxArray *basename_mx = mxGetField(M_mx, 0, "fname");
+  const mxArray* basename_mx = mxGetField(M_mx, 0, "fname");
   if (!(basename_mx && mxIsChar(basename_mx) && mxGetM(basename_mx) == 1))
     mexErrMsgTxt("M_.fname should be a character string");
-  std::string basename{mxArrayToString(basename_mx)};
+  std::string basename {mxArrayToString(basename_mx)};
 
-  const mxArray *endo_nbr_mx = mxGetField(M_mx, 0, "endo_nbr");
+  const mxArray* endo_nbr_mx = mxGetField(M_mx, 0, "endo_nbr");
   if (!(endo_nbr_mx && mxIsScalar(endo_nbr_mx) && mxIsNumeric(endo_nbr_mx)))
     mexErrMsgTxt("M_.endo_nbr should be a numeric scalar");
   mwIndex ny = static_cast<mwIndex>(mxGetScalar(endo_nbr_mx));
 
-  const mxArray *maximum_lag_mx = mxGetField(M_mx, 0, "maximum_lag");
+  const mxArray* maximum_lag_mx = mxGetField(M_mx, 0, "maximum_lag");
   if (!(maximum_lag_mx && mxIsScalar(maximum_lag_mx) && mxIsNumeric(maximum_lag_mx)))
     mexErrMsgTxt("M_.maximum_lag should be a numeric scalar");
   mwIndex maximum_lag = static_cast<mwIndex>(mxGetScalar(maximum_lag_mx));
 
-  const mxArray *dynamic_tmp_nbr_mx = mxGetField(M_mx, 0, "dynamic_tmp_nbr");
-  if (!(dynamic_tmp_nbr_mx && mxIsDouble(dynamic_tmp_nbr_mx) && mxGetNumberOfElements(dynamic_tmp_nbr_mx) >= 2)
+  const mxArray* dynamic_tmp_nbr_mx = mxGetField(M_mx, 0, "dynamic_tmp_nbr");
+  if (!(dynamic_tmp_nbr_mx && mxIsDouble(dynamic_tmp_nbr_mx)
+        && mxGetNumberOfElements(dynamic_tmp_nbr_mx) >= 2)
       || mxIsComplex(dynamic_tmp_nbr_mx) || mxIsSparse(dynamic_tmp_nbr_mx))
     mexErrMsgTxt("M_.dynamic_tmp_nbr should be a real dense array of at least 2 elements");
-  size_t ntt {static_cast<size_t>(mxGetPr(dynamic_tmp_nbr_mx)[0]) +
-    (compute_jacobian ? static_cast<size_t>(mxGetPr(dynamic_tmp_nbr_mx)[1]) : 0)};
+  size_t ntt {static_cast<size_t>(mxGetPr(dynamic_tmp_nbr_mx)[0])
+              + (compute_jacobian ? static_cast<size_t>(mxGetPr(dynamic_tmp_nbr_mx)[1]) : 0)};
 
-  const mxArray *has_external_function_mx = mxGetField(M_mx, 0, "has_external_function");
+  const mxArray* has_external_function_mx = mxGetField(M_mx, 0, "has_external_function");
   if (!(has_external_function_mx && mxIsLogicalScalar(has_external_function_mx)))
     mexErrMsgTxt("M_.has_external_function should be a logical scalar");
   bool has_external_function = static_cast<bool>(mxGetScalar(has_external_function_mx));
 
   // Extract various fields from options_
-  const mxArray *use_dll_mx = mxGetField(options_mx, 0, "use_dll");
+  const mxArray* use_dll_mx = mxGetField(options_mx, 0, "use_dll");
   if (!(use_dll_mx && mxIsLogicalScalar(use_dll_mx)))
     mexErrMsgTxt("options_.use_dll should be a logical scalar");
   bool use_dll = static_cast<bool>(mxGetScalar(use_dll_mx));
 
-  const mxArray *linear_mx = mxGetField(options_mx, 0, "linear");
+  const mxArray* linear_mx = mxGetField(options_mx, 0, "linear");
   if (!(linear_mx && mxIsLogicalScalar(linear_mx)))
     mexErrMsgTxt("options_.linear should be a logical scalar");
   bool linear = static_cast<bool>(mxGetScalar(linear_mx));
 
-  const mxArray *threads_mx = mxGetField(options_mx, 0, "threads");
+  const mxArray* threads_mx = mxGetField(options_mx, 0, "threads");
   if (!threads_mx)
     mexErrMsgTxt("Can't find field options_.threads");
-  const mxArray *num_threads_mx = mxGetField(threads_mx, 0, "perfect_foresight_problem");
+  const mxArray* num_threads_mx = mxGetField(threads_mx, 0, "perfect_foresight_problem");
   if (!(num_threads_mx && mxIsScalar(num_threads_mx) && mxIsNumeric(num_threads_mx)))
     mexErrMsgTxt("options_.threads.perfect_foresight_problem should be a numeric scalar");
   int num_threads = static_cast<int>(mxGetScalar(num_threads_mx));
@@ -95,72 +96,81 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
     mexErrMsgTxt("periods should be a numeric scalar");
   mwIndex periods = static_cast<mwIndex>(mxGetScalar(periods_mx));
 
-  if (!(mxIsDouble(y_mx) && mxGetM(y_mx) == static_cast<size_t>(ny*periods) && mxGetN(y_mx) == 1))
+  if (!(mxIsDouble(y_mx) && mxGetM(y_mx) == static_cast<size_t>(ny * periods) && mxGetN(y_mx) == 1))
     mexErrMsgTxt("y should be a double precision column-vector of M_.endo_nbr*periods elements");
-  const double *y = mxGetPr(y_mx);
+  const double* y = mxGetPr(y_mx);
 
   if (!(mxIsDouble(y0_mx) && mxGetM(y0_mx) == static_cast<size_t>(ny) && mxGetN(y0_mx) == 1))
     mexErrMsgTxt("y0 should be a double precision column-vector of M_.endo_nbr elements");
-  const double *y0 = mxGetPr(y0_mx);
+  const double* y0 = mxGetPr(y0_mx);
 
   if (!(mxIsDouble(yT_mx) && mxGetM(yT_mx) == static_cast<size_t>(ny) && mxGetN(yT_mx) == 1))
     mexErrMsgTxt("yT should be a double precision column-vector of M_.endo_nbr elements");
-  const double *yT = mxGetPr(yT_mx);
+  const double* yT = mxGetPr(yT_mx);
 
-  if (!(mxIsDouble(exo_path_mx) && mxGetM(exo_path_mx) >= static_cast<size_t>(periods+maximum_lag)))
-    mexErrMsgTxt("exo_path should be a double precision matrix with at least periods+M_.maximum_lag rows");
+  if (!(mxIsDouble(exo_path_mx)
+        && mxGetM(exo_path_mx) >= static_cast<size_t>(periods + maximum_lag)))
+    mexErrMsgTxt(
+        "exo_path should be a double precision matrix with at least periods+M_.maximum_lag rows");
   mwIndex nx = static_cast<mwIndex>(mxGetN(exo_path_mx));
   size_t nb_row_x = mxGetM(exo_path_mx);
-  const double *exo_path = mxGetPr(exo_path_mx);
+  const double* exo_path = mxGetPr(exo_path_mx);
 
-  const mxArray *g1_sparse_rowval_mx {mxGetField(M_mx, 0, "dynamic_g1_sparse_rowval")};
+  const mxArray* g1_sparse_rowval_mx {mxGetField(M_mx, 0, "dynamic_g1_sparse_rowval")};
   if (!(mxIsInt32(g1_sparse_rowval_mx)))
     mexErrMsgTxt("M_.dynamic_g1_sparse_rowval should be an int32 vector");
 #if MX_HAS_INTERLEAVED_COMPLEX
-  const int32_T *g1_sparse_rowval {mxGetInt32s(g1_sparse_rowval_mx)};
+  const int32_T* g1_sparse_rowval {mxGetInt32s(g1_sparse_rowval_mx)};
 #else
-  const int32_T *g1_sparse_rowval {static_cast<const int32_T *>(mxGetData(g1_sparse_rowval_mx))};
+  const int32_T* g1_sparse_rowval {static_cast<const int32_T*>(mxGetData(g1_sparse_rowval_mx))};
 #endif
 
-  const mxArray *g1_sparse_colval_mx {mxGetField(M_mx, 0, "dynamic_g1_sparse_colval")};
+  const mxArray* g1_sparse_colval_mx {mxGetField(M_mx, 0, "dynamic_g1_sparse_colval")};
   if (!(mxIsInt32(g1_sparse_colval_mx)))
     mexErrMsgTxt("M_.dynamic_g1_sparse_colval should be an int32 vector");
   if (mxGetNumberOfElements(g1_sparse_colval_mx) != mxGetNumberOfElements(g1_sparse_rowval_mx))
-    mexErrMsgTxt("M_.dynamic_g1_sparse_colval should have the same length as M_.dynamic_g1_sparse_rowval");
-
-  const mxArray *g1_sparse_colptr_mx {mxGetField(M_mx, 0, "dynamic_g1_sparse_colptr")};
-  if (!(mxIsInt32(g1_sparse_colptr_mx) && mxGetNumberOfElements(g1_sparse_colptr_mx) == static_cast<size_t>(3*ny+nx+1)))
-    mexErrMsgTxt(("M_.dynamic_g1_sparse_colptr should be an int32 vector with " + std::to_string(3*ny+nx+1) + " elements").c_str());
+    mexErrMsgTxt(
+        "M_.dynamic_g1_sparse_colval should have the same length as M_.dynamic_g1_sparse_rowval");
+
+  const mxArray* g1_sparse_colptr_mx {mxGetField(M_mx, 0, "dynamic_g1_sparse_colptr")};
+  if (!(mxIsInt32(g1_sparse_colptr_mx)
+        && mxGetNumberOfElements(g1_sparse_colptr_mx) == static_cast<size_t>(3 * ny + nx + 1)))
+    mexErrMsgTxt(("M_.dynamic_g1_sparse_colptr should be an int32 vector with "
+                  + std::to_string(3 * ny + nx + 1) + " elements")
+                     .c_str());
 #if MX_HAS_INTERLEAVED_COMPLEX
-  const int32_T *g1_sparse_colptr {mxGetInt32s(g1_sparse_colptr_mx)};
+  const int32_T* g1_sparse_colptr {mxGetInt32s(g1_sparse_colptr_mx)};
 #else
-  const int32_T *g1_sparse_colptr {static_cast<const int32_T *>(mxGetData(g1_sparse_colptr_mx))};
+  const int32_T* g1_sparse_colptr {static_cast<const int32_T*>(mxGetData(g1_sparse_colptr_mx))};
 #endif
-  if (static_cast<size_t>(g1_sparse_colptr[3*ny+nx])-1 != mxGetNumberOfElements(g1_sparse_rowval_mx))
-    mexErrMsgTxt("The size of M_.dynamic_g1_sparse_rowval is not consistent with the last element of M_.dynamic_g1_sparse_colptr");
+  if (static_cast<size_t>(g1_sparse_colptr[3 * ny + nx]) - 1
+      != mxGetNumberOfElements(g1_sparse_rowval_mx))
+    mexErrMsgTxt("The size of M_.dynamic_g1_sparse_rowval is not consistent with the last element "
+                 "of M_.dynamic_g1_sparse_colptr");
 
   if (!(mxIsDouble(params_mx) && mxGetN(params_mx) == 1))
     mexErrMsgTxt("params should be a double precision column-vector");
-  const double *params = mxGetPr(params_mx);
+  const double* params = mxGetPr(params_mx);
 
   if (!(mxIsDouble(steady_state_mx) && mxGetN(steady_state_mx) == 1))
     mexErrMsgTxt("steady_state should be a double precision column-vector");
-  const double *steady_state = mxGetPr(steady_state_mx);
+  const double* steady_state = mxGetPr(steady_state_mx);
 
   // Allocate output matrices
-  plhs[0] = mxCreateDoubleMatrix(periods*ny, 1, mxREAL);
-  double *stacked_residual = mxGetPr(plhs[0]);
+  plhs[0] = mxCreateDoubleMatrix(periods * ny, 1, mxREAL);
+  double* stacked_residual = mxGetPr(plhs[0]);
 
   /* Number of non-zero values in the stacked Jacobian.
      Contemporaneous derivatives appear at all periods, while lag or lead
      derivatives appear at all periods except one. */
-  mwSize nzmax {static_cast<mwSize>((g1_sparse_colptr[3*ny]-1)*(periods-1) + (g1_sparse_colptr[2*ny]-g1_sparse_colptr[ny]))};
+  mwSize nzmax {static_cast<mwSize>((g1_sparse_colptr[3 * ny] - 1) * (periods - 1)
+                                    + (g1_sparse_colptr[2 * ny] - g1_sparse_colptr[ny]))};
 
-  double *stacked_jacobian = nullptr;
+  double* stacked_jacobian = nullptr;
   mwIndex *ir = nullptr, *jc = nullptr;
   if (compute_jacobian)
     {
-      plhs[1] = mxCreateSparse(periods*ny, periods*ny, nzmax, mxREAL);
+      plhs[1] = mxCreateSparse(periods * ny, periods * ny, nzmax, mxREAL);
       stacked_jacobian = mxGetPr(plhs[1]);
       ir = mxGetIr(plhs[1]);
       jc = mxGetJc(plhs[1]);
@@ -174,14 +184,18 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
         for (mwIndex j {0}; j < ny; j++) // Column within the period (i.e. variable)
           {
             if (T > 0)
-              for (int32_T idx {g1_sparse_colptr[2*ny+j]-1}; idx < g1_sparse_colptr[2*ny+j+1]-1; idx++)
-                ir[k++] = (T-1)*ny + g1_sparse_rowval[idx]-1; // Derivatives w.r.t. y_{t+1} in T-1
-            for (int32_T idx {g1_sparse_colptr[ny+j]-1}; idx < g1_sparse_colptr[ny+j+1]-1; idx++)
-              ir[k++] = T*ny + g1_sparse_rowval[idx]-1; // Derivatives w.r.t. y_t in T
-            if (T < periods-1)
-              for (int32_T idx {g1_sparse_colptr[j]-1}; idx < g1_sparse_colptr[j+1]-1; idx++)
-                ir[k++] = (T+1)*ny + g1_sparse_rowval[idx]-1; // Derivatives w.r.t. y_{t-1} in T+1
-            jc[T*ny+j+1] = k;
+              for (int32_T idx {g1_sparse_colptr[2 * ny + j] - 1};
+                   idx < g1_sparse_colptr[2 * ny + j + 1] - 1; idx++)
+                ir[k++]
+                    = (T - 1) * ny + g1_sparse_rowval[idx] - 1; // Derivatives w.r.t. y_{t+1} in T-1
+            for (int32_T idx {g1_sparse_colptr[ny + j] - 1}; idx < g1_sparse_colptr[ny + j + 1] - 1;
+                 idx++)
+              ir[k++] = T * ny + g1_sparse_rowval[idx] - 1; // Derivatives w.r.t. y_t in T
+            if (T < periods - 1)
+              for (int32_T idx {g1_sparse_colptr[j] - 1}; idx < g1_sparse_colptr[j + 1] - 1; idx++)
+                ir[k++]
+                    = (T + 1) * ny + g1_sparse_rowval[idx] - 1; // Derivatives w.r.t. y_{t-1} in T+1
+            jc[T * ny + j + 1] = k;
           }
     }
 
@@ -197,59 +211,63 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
     // Allocate (thread-private) model evaluator (which allocates space for temporaries)
     std::unique_ptr<DynamicModelCaller> m;
     if (use_dll)
-      m = std::make_unique<DynamicModelDllCaller>(ntt, ny, nx, params, steady_state, g1_sparse_colptr, linear, compute_jacobian);
+      m = std::make_unique<DynamicModelDllCaller>(ntt, ny, nx, params, steady_state,
+                                                  g1_sparse_colptr, linear, compute_jacobian);
     else
-      m = std::make_unique<DynamicModelMatlabCaller>(basename, ny, nx, params_mx, steady_state_mx, g1_sparse_rowval_mx, g1_sparse_colval_mx, g1_sparse_colptr_mx, linear, compute_jacobian);
+      m = std::make_unique<DynamicModelMatlabCaller>(basename, ny, nx, params_mx, steady_state_mx,
+                                                     g1_sparse_rowval_mx, g1_sparse_colval_mx,
+                                                     g1_sparse_colptr_mx, linear, compute_jacobian);
 
-    // Main computing loop
+      // Main computing loop
 #pragma omp for
     for (mwIndex T = 0; T < periods; T++)
       {
         // Fill vector of dynamic variables
-        if (T > 0 && T < periods-1)
-          std::copy_n(y+(T-1)*ny, 3*ny, m->y());
+        if (T > 0 && T < periods - 1)
+          std::copy_n(y + (T - 1) * ny, 3 * ny, m->y());
         else if (T > 0) // Last simulation period
           {
-            std::copy_n(y+(T-1)*ny, 2*ny, m->y());
-            std::copy_n(yT, ny, m->y() + 2*ny);
+            std::copy_n(y + (T - 1) * ny, 2 * ny, m->y());
+            std::copy_n(yT, ny, m->y() + 2 * ny);
           }
-        else if (T < periods-1) // First simulation period
+        else if (T < periods - 1) // First simulation period
           {
             std::copy_n(y0, ny, m->y());
-            std::copy_n(y+T*ny, 2*ny, m->y() + ny);
+            std::copy_n(y + T * ny, 2 * ny, m->y() + ny);
           }
         else // Special case: periods=1 (and so T=0)
           {
             std::copy_n(y0, ny, m->y());
             std::copy_n(y, ny, m->y() + ny);
-            std::copy_n(yT, ny, m->y() + 2*ny);
+            std::copy_n(yT, ny, m->y() + 2 * ny);
           }
 
         // Fill exogenous
         for (mwIndex j {0}; j < nx; j++)
-          m->x()[j] = exo_path[T+maximum_lag + nb_row_x*j];
+          m->x()[j] = exo_path[T + maximum_lag + nb_row_x * j];
 
         // Compute the residual and Jacobian, and fill the stacked residual
-        m->eval(stacked_residual+T*ny);
+        m->eval(stacked_residual + T * ny);
 
         if (compute_jacobian)
           {
             // Fill the stacked jacobian
-            for (mwIndex col { T > 1 ? (T-1)*ny : 0 }; // We can't use std::max() here, because mwIndex is unsigned under MATLAB
-                 col < std::min(periods*ny, (T+2)*ny); col++)
+            for (mwIndex col {T > 1 ? (T - 1) * ny : 0}; // We can't use std::max() here, because
+                                                         // mwIndex is unsigned under MATLAB
+                 col < std::min(periods * ny, (T + 2) * ny); col++)
               {
                 mwIndex k = jc[col];
-                while (k < jc[col+1])
+                while (k < jc[col + 1])
                   {
-                    if (ir[k] >= (T+1)*ny)
+                    if (ir[k] >= (T + 1) * ny)
                       break; // Nothing to copy for this column
-                    if (ir[k] >= T*ny)
+                    if (ir[k] >= T * ny)
                       {
                         /* Within the current column, this is the first line of
                            the stacked Jacobian that contains elements from the
                            (small) Jacobian just computed, so copy the whole
                            column of the latter to the former. */
-                        m->copy_jacobian_column(col - (T-1)*ny, stacked_jacobian + k);
+                        m->copy_jacobian_column(col - (T - 1) * ny, stacked_jacobian + k);
                         break;
                       }
                     k++;
@@ -273,9 +291,9 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
          to those extra zeros. This makes a significant speed difference when
          inversing the Jacobian for some large models. */
       mwIndex k_orig = 0, k_new = 0;
-      for (mwIndex col = 0; col < periods*ny; col++)
+      for (mwIndex col = 0; col < periods * ny; col++)
         {
-          while (k_orig < jc[col+1])
+          while (k_orig < jc[col + 1])
             {
               if (stacked_jacobian[k_orig] != 0.0)
                 {
@@ -288,7 +306,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
                 }
               k_orig++;
             }
-          jc[col+1] = k_new;
+          jc[col + 1] = k_new;
         }
     }
 
diff --git a/mex/sources/sobol/gaussian.hh b/mex/sources/sobol/gaussian.hh
index 7352f50f801919ab47f93db452009ece686d0054..b538c599a5e82a090cc6542ef346868e56cebbb2 100644
--- a/mex/sources/sobol/gaussian.hh
+++ b/mex/sources/sobol/gaussian.hh
@@ -22,9 +22,9 @@
 ** AUTHOR(S): stephane DOT adjemian AT univ DASH lemans DOT fr
 */
 
+#include <algorithm>
 #include <cmath>
 #include <limits>
-#include <algorithm>
 #include <numbers>
 
 #include <omp.h>
@@ -44,45 +44,21 @@ icdf(const T uniform)
 **
 */
 {
-  static T A[6] =
-    {
-     -3.969683028665376e+01,
-     2.209460984245205e+02,
-     -2.759285104469687e+02,
-     1.383577518672690e+02,
-     -3.066479806614716e+01,
-     2.506628277459239e+00
-    };
-  static T B[5] =
-    {
-     -5.447609879822406e+01,
-     1.615858368580409e+02,
-     -1.556989798598866e+02,
-     6.680131188771972e+01,
-     -1.328068155288572e+01
-    };
-  static T C[6] =
-    {
-     -7.784894002430293e-03,
-     -3.223964580411365e-01,
-     -2.400758277161838e+00,
-     -2.549732539343734e+00,
-     4.374664141464968e+00,
-     2.938163982698783e+00
-    };
-  static T D[4] =
-    {
-     7.784695709041462e-03,
-     3.224671290700398e-01,
-     2.445134137142996e+00,
-     3.754408661907416e+00
-    };
+  static T A[6] = {-3.969683028665376e+01, 2.209460984245205e+02,  -2.759285104469687e+02,
+                   1.383577518672690e+02,  -3.066479806614716e+01, 2.506628277459239e+00};
+  static T B[5] = {-5.447609879822406e+01, 1.615858368580409e+02, -1.556989798598866e+02,
+                   6.680131188771972e+01, -1.328068155288572e+01};
+  static T C[6] = {-7.784894002430293e-03, -3.223964580411365e-01, -2.400758277161838e+00,
+                   -2.549732539343734e+00, 4.374664141464968e+00,  2.938163982698783e+00};
+  static T D[4] = {7.784695709041462e-03, 3.224671290700398e-01, 2.445134137142996e+00,
+                   3.754408661907416e+00};
   T gaussian = static_cast<T>(0.0);
   if (0 < uniform && uniform < lb)
     {
       T tmp;
-      tmp = sqrt(-2*log(uniform));
-      gaussian = (((((C[0]*tmp+C[1])*tmp+C[2])*tmp+C[3])*tmp+C[4])*tmp+C[5])/((((D[0]*tmp+D[1])*tmp+D[2])*tmp+D[3])*tmp+1);
+      tmp = sqrt(-2 * log(uniform));
+      gaussian = (((((C[0] * tmp + C[1]) * tmp + C[2]) * tmp + C[3]) * tmp + C[4]) * tmp + C[5])
+                 / ((((D[0] * tmp + D[1]) * tmp + D[2]) * tmp + D[3]) * tmp + 1);
     }
   else
     {
@@ -90,25 +66,29 @@ icdf(const T uniform)
         {
           T tmp, TMP;
           tmp = uniform - .5;
-          TMP = tmp*tmp;
-          gaussian = (((((A[0]*TMP+A[1])*TMP+A[2])*TMP+A[3])*TMP+A[4])*TMP+A[5])*tmp/(((((B[0]*TMP+B[1])*TMP+B[2])*TMP+B[3])*TMP+B[4])*TMP+1);
+          TMP = tmp * tmp;
+          gaussian = (((((A[0] * TMP + A[1]) * TMP + A[2]) * TMP + A[3]) * TMP + A[4]) * TMP + A[5])
+                     * tmp
+                     / (((((B[0] * TMP + B[1]) * TMP + B[2]) * TMP + B[3]) * TMP + B[4]) * TMP + 1);
         }
       else
         {
           if (ub < uniform && uniform < 1)
             {
               T tmp;
-              tmp = sqrt(-2*log(1-uniform));
-              gaussian = -(((((C[0]*tmp+C[1])*tmp+C[2])*tmp+C[3])*tmp+C[4])*tmp+C[5])/((((D[0]*tmp+D[1])*tmp+D[2])*tmp+D[3])*tmp+1);
+              tmp = sqrt(-2 * log(1 - uniform));
+              gaussian
+                  = -(((((C[0] * tmp + C[1]) * tmp + C[2]) * tmp + C[3]) * tmp + C[4]) * tmp + C[5])
+                    / ((((D[0] * tmp + D[1]) * tmp + D[2]) * tmp + D[3]) * tmp + 1);
             }
         }
     }
   if (0 < uniform && uniform < 1)
     {
       T tmp, tmp_;
-      tmp = .5*erfc(-gaussian/sqrt(2.0))-uniform;
-      tmp_ = tmp*sqrt(2*numbers::pi)*exp(.5*gaussian*gaussian);
-      gaussian = gaussian - tmp_/(1+.5*gaussian*tmp_);
+      tmp = .5 * erfc(-gaussian / sqrt(2.0)) - uniform;
+      tmp_ = tmp * sqrt(2 * numbers::pi) * exp(.5 * gaussian * gaussian);
+      gaussian = gaussian - tmp_ / (1 + .5 * gaussian * tmp_);
     }
   if (uniform == 0)
     gaussian = -numeric_limits<T>::infinity();
@@ -121,7 +101,7 @@ icdf(const T uniform)
 
 template<typename T>
 void
-icdfm(int n, T *U)
+icdfm(int n, T* U)
 {
 #pragma omp parallel for
   for (int i = 0; i < n; i++)
@@ -131,52 +111,52 @@ icdfm(int n, T *U)
 
 template<typename T>
 void
-icdfmSigma(int d, int n, T *U, const double *LowerCholSigma)
+icdfmSigma(int d, int n, T* U, const double* LowerCholSigma)
 {
   double one = 1.0;
   double zero = 0.0;
   blas_int dd(d);
   blas_int nn(n);
-  icdfm(n*d, U);
-  double tmp[n*d];
+  icdfm(n * d, U);
+  double tmp[n * d];
   dgemm("N", "N", &dd, &nn, &dd, &one, LowerCholSigma, &dd, U, &dd, &zero, tmp, &dd);
-  copy_n(tmp, d*n, U);
+  copy_n(tmp, d * n, U);
 }
 
 template<typename T>
 void
-usphere(int d, int n, T *U)
+usphere(int d, int n, T* U)
 {
-  icdfm(n*d, U);
+  icdfm(n * d, U);
 #pragma omp parallel for
   for (int j = 0; j < n; j++) // sequence index.
     {
-      int k = j*d;
+      int k = j * d;
       double norm = 0.0;
       for (int i = 0; i < d; i++) // dimension index.
-        norm = norm + U[k+i]*U[k+i];
+        norm = norm + U[k + i] * U[k + i];
 
       norm = sqrt(norm);
       for (int i = 0; i < d; i++) // dimension index.
-        U[k+i] = U[k+i]/norm;
+        U[k + i] = U[k + i] / norm;
     }
 }
 
 template<typename T>
 void
-usphereRadius(int d, int n, double radius, T *U)
+usphereRadius(int d, int n, double radius, T* U)
 {
-  icdfm(n*d, U);
+  icdfm(n * d, U);
 #pragma omp parallel for
   for (int j = 0; j < n; j++) // sequence index.
     {
-      int k = j*d;
+      int k = j * d;
       double norm = 0.0;
       for (int i = 0; i < d; i++) // dimension index.
-        norm = norm + U[k+i]*U[k+i];
+        norm = norm + U[k + i] * U[k + i];
 
       norm = sqrt(norm);
       for (int i = 0; i < d; i++) // dimension index.
-        U[k+i] = radius*U[k+i]/norm;
+        U[k + i] = radius * U[k + i] / norm;
     }
 }
diff --git a/mex/sources/sobol/qmc_sequence.cc b/mex/sources/sobol/qmc_sequence.cc
index 237fb0019cb6d69bb51e1a671695ddd4c2712bde..22854aa14e11e0a0f463518f31eaf80a8a634eb1 100644
--- a/mex/sources/sobol/qmc_sequence.cc
+++ b/mex/sources/sobol/qmc_sequence.cc
@@ -23,11 +23,11 @@
 
 #include <dynmex.h>
 
-#include "sobol.hh"
 #include "gaussian.hh"
+#include "sobol.hh"
 
 void
-mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
+mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[])
 {
   /*
   ** INPUTS:
@@ -38,8 +38,10 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
   **                                   1 ⇒ gaussian,
   **                                   2 ⇒ uniform on an hypershere.
   ** prhs[3]    [integer]    scalar, sequence size.
-  ** prhs[4]    [double]     dimension×2 array, lower and upper bounds of the hypercube (default is 0-1 in all dimensions) if prhs[2]==0,
-  **                         dimension×dimension array, covariance of the multivariate gaussian distribution of prhs[2]==1 (default is the identity matrix),
+  ** prhs[4]    [double]     dimension×2 array, lower and upper bounds of the hypercube (default is
+  **                         0-1 in all dimensions) if prhs[2]==0,
+  **                         dimension×dimension array, covariance of the multivariate gaussian
+  **                         distribution of prhs[2]==1 (default is the identity matrix),
   **                         scalar, radius of the hypershere if prhs[2]==2 (default is one).
   **
   ** OUTPUTS:
@@ -76,7 +78,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
 #if MX_HAS_INTERLEAVED_COMPLEX
   int64_T seed = *mxGetInt64s(prhs[1]);
 #else
-  int64_T seed = *static_cast<int64_T *>(mxGetData(prhs[1]));
+  int64_T seed = *static_cast<int64_T*>(mxGetData(prhs[1]));
 #endif
 
   /*
@@ -91,16 +93,20 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
     error_flag_3 = 1;
 
   if (error_flag_3 == 1)
-    mexErrMsgTxt("qmc_sequence:: Third input (type of QMC sequence) has to be an integer equal to 0, 1 or 2!");
+    mexErrMsgTxt("qmc_sequence:: Third input (type of QMC sequence) has to be an integer equal to "
+                 "0, 1 or 2!");
 
   /*
   ** Test dimension ≥ 2 when type==2
   */
   if (type == 2 && dimension < 2)
-    mexErrMsgTxt("qmc_sequence:: First input (dimension) has to be greater than 1 for a uniform QMC on an hypershere!");
+    mexErrMsgTxt("qmc_sequence:: First input (dimension) has to be greater than 1 for a uniform "
+                 "QMC on an hypershere!");
 
   else if (dimension > DIM_MAX)
-    mexErrMsgTxt(("qmc_sequence:: First input (dimension) has to be smaller than " + to_string(DIM_MAX) + " !").c_str());
+    mexErrMsgTxt(("qmc_sequence:: First input (dimension) has to be smaller than "
+                  + to_string(DIM_MAX) + " !")
+                     .c_str());
 
   /*
   ** Test the optional fourth input argument and assign it to sequence_size.
@@ -113,7 +119,8 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
     {
       sequence_size = static_cast<int>(mxGetScalar(prhs[3]));
       if (sequence_size <= 0)
-        mexErrMsgTxt("qmc_sequence:: Fourth input (qmc sequence size) has to be a positive integer!");
+        mexErrMsgTxt(
+            "qmc_sequence:: Fourth input (qmc sequence size) has to be a positive integer!");
     }
   else
     sequence_size = 1;
@@ -124,17 +131,22 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
   if (nrhs > 4 && type == 0
       && !(mxIsDouble(prhs[4]) && !mxIsComplex(prhs[4]) && !mxIsSparse(prhs[4])
            && mxGetN(prhs[4]) == 2
-           && static_cast<int>(mxGetM(prhs[4])) == dimension)) // Sequence of uniformly distributed numbers in an hypercube
-    mexErrMsgTxt("qmc_sequence:: The fifth input argument must be a real dense array with two columns and number of lines equal to dimension (first input argument)!");
+           && static_cast<int>(mxGetM(prhs[4]))
+                  == dimension)) // Sequence of uniformly distributed numbers in an hypercube
+    mexErrMsgTxt("qmc_sequence:: The fifth input argument must be a real dense array with two "
+                 "columns and number of lines equal to dimension (first input argument)!");
 
   if (nrhs > 4 && type == 1
       && !(mxIsDouble(prhs[4]) && !mxIsComplex(prhs[4]) && !mxIsSparse(prhs[4])
            && static_cast<int>(mxGetN(prhs[4])) == dimension
-           && static_cast<int>(mxGetM(prhs[4])) == dimension)) // Sequence of normally distributed numbers
-    mexErrMsgTxt("qmc_sequence:: The fifth input argument must be a real dense square matrix (whose dimension is given by the first input argument)!");
+           && static_cast<int>(mxGetM(prhs[4]))
+                  == dimension)) // Sequence of normally distributed numbers
+    mexErrMsgTxt("qmc_sequence:: The fifth input argument must be a real dense square matrix "
+                 "(whose dimension is given by the first input argument)!");
 
   if (nrhs > 4 && type == 2
-      && !(mxIsScalar(prhs[4]) && mxIsNumeric(prhs[4]))) // Sequence of uniformly distributed numbers on a hypershere
+      && !(mxIsScalar(prhs[4])
+           && mxIsNumeric(prhs[4]))) // Sequence of uniformly distributed numbers on a hypershere
     mexErrMsgTxt("qmc_sequence:: The fifth input argument must be a numeric scalar!");
 
   const double *lower_bounds = nullptr, *upper_bounds = nullptr;
@@ -145,7 +157,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
       upper_bounds = lower_bounds + dimension;
       unit_hypercube_flag = 0;
     }
-  const double *cholcov = nullptr;
+  const double* cholcov = nullptr;
   int identity_covariance_matrix = 1;
   if (type == 1 && nrhs > 4)
     {
@@ -165,7 +177,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
   ** Initialize outputs of the mex file.
   */
   plhs[0] = mxCreateDoubleMatrix(dimension, sequence_size, mxREAL);
-  double *qmc_draws = mxGetPr(plhs[0]);
+  double* qmc_draws = mxGetPr(plhs[0]);
   int64_T seed_out;
 
   if (sequence_size == 1)
@@ -181,7 +193,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
   else if (type == 1) // Normal QMC sequence in ℝⁿ
     {
       if (identity_covariance_matrix == 1)
-        icdfm(dimension*sequence_size, qmc_draws);
+        icdfm(dimension * sequence_size, qmc_draws);
       else
         icdfmSigma(dimension, sequence_size, qmc_draws, cholcov);
     }
@@ -199,7 +211,7 @@ mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
 #if MX_HAS_INTERLEAVED_COMPLEX
       *mxGetInt64s(plhs[1]) = seed_out;
 #else
-      *(static_cast<int64_T *>(mxGetData(plhs[1]))) = seed_out;
+      *(static_cast<int64_T*>(mxGetData(plhs[1]))) = seed_out;
 #endif
     }
   if (nlhs >= 3)
diff --git a/mex/sources/sobol/sobol.hh b/mex/sources/sobol/sobol.hh
index 8dd62ccdeac0c71e314ea7e182b845f5c18f0f24..2531d40f68f1879c45310d74e73d95b526d06a20 100644
--- a/mex/sources/sobol/sobol.hh
+++ b/mex/sources/sobol/sobol.hh
@@ -27,37 +27,38 @@ constexpr int DIM_MAX = 1111;
 extern "C"
 {
 #define i8_sobol FORTRAN_WRAPPER(i8_sobol)
-  void i8_sobol(const int64_t *dim_num, int64_t *seed, double *quasi);
+  void i8_sobol(const int64_t* dim_num, int64_t* seed, double* quasi);
 }
 
 inline void
-next_sobol(int dim_num, int64_t *seed, double *quasi)
+next_sobol(int dim_num, int64_t* seed, double* quasi)
 {
   int64_t dim_num2 {dim_num};
   i8_sobol(&dim_num2, seed, quasi);
 }
 
 inline int64_t
-sobol_block(int dimension, int block_size, int64_t seed, double *block)
+sobol_block(int dimension, int block_size, int64_t seed, double* block)
 {
   for (int iter = 0; iter < block_size; iter++)
-    next_sobol(dimension, &seed, &block[iter*dimension]);
+    next_sobol(dimension, &seed, &block[iter * dimension]);
   return seed;
 }
 
 template<typename T>
 void
-expand_unit_hypercube(int dimension, int block_size, T *block, const T *lower_bound, const T *upper_bound)
+expand_unit_hypercube(int dimension, int block_size, T* block, const T* lower_bound,
+                      const T* upper_bound)
 {
-  T *hypercube_length = new T[dimension];
+  T* hypercube_length = new T[dimension];
   for (int dim = 0; dim < dimension; dim++)
-    hypercube_length[dim] = upper_bound[dim]-lower_bound[dim];
+    hypercube_length[dim] = upper_bound[dim] - lower_bound[dim];
 
   int base = 0;
   for (int sim = 0; sim < block_size; sim++)
     {
       for (int dim = 0; dim < dimension; dim++)
-        block[base+dim] = lower_bound[dim] + hypercube_length[dim]*block[base+dim];
+        block[base + dim] = lower_bound[dim] + hypercube_length[dim] * block[base + dim];
       base += dimension;
     }
   delete[] hypercube_length;