diff --git a/src/DynareMain.cc b/src/DynareMain.cc
index d9621dc4a241a2cac094a30e0f2b392c6b4774a7..e64b44ae624e93466e01b52c5d42261d12eec1da 100644
--- a/src/DynareMain.cc
+++ b/src/DynareMain.cc
@@ -38,12 +38,17 @@
 #include "ConfigFile.hh"
 #include "ModFile.hh"
 
-/* Prototype for second part of main function
-   Splitting main() in two parts was necessary because ParsingDriver.h and MacroDriver.h can't be
+/* Prototype for the function that handles the macro-expansion of the .mod file
+   Splitting this out was necessary because ParsingDriver.hh and macro/Driver.hh can't be
    included simultaneously (because of Bison limitations).
+
+   Function can be found in: MacroExpandModFile.cc
 */
-void main1(const string &filename, const string &basename, istream &modfile, bool debug, bool save_macro, string &save_macro_file,
-           bool line_macro, const vector<pair<string, string>> &defines, vector<filesystem::path> &paths, stringstream &macro_output);
+stringstream
+macroExpandModFile(const string &filename, const string &basename, const istream &modfile,
+                   bool debug, bool save_macro, string save_macro_file, bool line_macro,
+                   const vector<pair<string, string>> &defines,
+                   vector<filesystem::path> paths);
 
 void
 usage()
@@ -424,9 +429,10 @@ main(int argc, char **argv)
   /*
    * Macro-expand MOD file
    */
-  stringstream macro_output;
-  main1(filename, basename, modfile, debug, save_macro, save_macro_file, line_macro,
-        defines, paths, macro_output);
+  stringstream macro_output =
+    macroExpandModFile(filename, basename, modfile, debug, save_macro,
+                       move(save_macro_file), line_macro,
+                       defines, move(paths));
 
   if (only_macro)
     return EXIT_SUCCESS;
diff --git a/src/DynareMain1.cc b/src/MacroExpandModFile.cc
similarity index 79%
rename from src/DynareMain1.cc
rename to src/MacroExpandModFile.cc
index b8d9c8b73752b6ea1ab8fe396300375490d7792a..8a3fd6091d4e0daba61f31577946521e250a7d84 100644
--- a/src/DynareMain1.cc
+++ b/src/MacroExpandModFile.cc
@@ -17,22 +17,25 @@
  * along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <regex>
 #include <sstream>
 #include <fstream>
 #include <filesystem>
 #include <algorithm>
-#include <regex>
 
 #include "macro/Driver.hh"
 
-void
-main1(const string &filename, const string &basename, istream &modfile, bool debug, bool save_macro, string &save_macro_file,
-      bool line_macro, const vector<pair<string, string>> &defines, vector<filesystem::path> &paths, stringstream &macro_output)
+stringstream
+macroExpandModFile(const string &filename, const string &basename, const istream &modfile,
+                   bool debug, bool save_macro, string save_macro_file, bool line_macro,
+                   const vector<pair<string, string>> &defines,
+                   vector<filesystem::path> paths)
 {
   // Do macro processing
+  stringstream macro_output;
   macro::Environment env = macro::Environment();
   macro::Driver m(env);
-  m.parse(filename, basename, modfile, macro_output, debug, defines, paths);
+  m.parse(filename, basename, modfile, debug, defines, paths, macro_output);
   if (save_macro)
     {
       if (save_macro_file.empty())
@@ -55,4 +58,5 @@ main1(const string &filename, const string &basename, istream &modfile, bool deb
       macro_output_file << str;
       macro_output_file.close();
     }
+  return macro_output;
 }
diff --git a/src/Makefile.am b/src/Makefile.am
index ccd508d5ee30b8846cae039ce008dafd071e09ad..91211bdd9661c2ee878e5cbc23a995509dbd21eb 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -43,7 +43,7 @@ dynare_m_SOURCES = \
 	MinimumFeedbackSet.cc \
 	MinimumFeedbackSet.hh \
 	DynareMain.cc \
-	DynareMain1.cc \
+	MacroExpandModFile.cc \
 	CodeInterpreter.hh \
 	ExternalFunctionsTable.cc \
 	ExternalFunctionsTable.hh \
diff --git a/src/macro/Directives.cc b/src/macro/Directives.cc
index e84b642198c009fb8e7e86f5c68e2f2c1340ce6d..b40e23531953116948e035a2a6aab4e60227156d 100644
--- a/src/macro/Directives.cc
+++ b/src/macro/Directives.cc
@@ -75,7 +75,7 @@ Include::interpret(ostream &output, vector<filesystem::path> &paths)
       // Calling `string()` method on filename and filename.stem() because of bug in
       // MinGW 8.3.0 that ignores implicit conversion to string from filename::path.
       // Test if bug exists when version of MinGW is upgraded on Debian runners
-      m.parse(filename.string(), filename.stem().string(), incfile, output, false, {}, paths);
+      m.parse(filename.string(), filename.stem().string(), incfile, false, {}, paths, output);
     }
   catch (StackTrace &ex)
     {
diff --git a/src/macro/Driver.cc b/src/macro/Driver.cc
index 25d12e2dcde7c773b17fc396d771fb37a53c2593..c05ec35bfafef3d570c91505efd257776b21ece9 100644
--- a/src/macro/Driver.cc
+++ b/src/macro/Driver.cc
@@ -23,9 +23,9 @@
 using namespace macro;
 
 void
-Driver::parse(const string &file_arg, const string &basename_arg, istream &modfile,
-              ostream &output, bool debug, const vector<pair<string, string>> &defines,
-              vector<filesystem::path> &paths)
+Driver::parse(const string &file_arg, const string &basename_arg, const istream &modfile,
+              bool debug, const vector<pair<string, string>> &defines,
+              vector<filesystem::path> &paths, ostream &output)
 {
   file = file_arg;
   basename = basename_arg;
@@ -37,7 +37,7 @@ Driver::parse(const string &file_arg, const string &basename_arg, istream &modfi
         command_line_defines_with_endl << "@#define " << var << " = " << val << endl;
       Driver m(env);
       istream is(command_line_defines_with_endl.rdbuf());
-      m.parse("command_line_defines", "command_line_defines", is, output, debug, {}, paths);
+      m.parse("command_line_defines", "command_line_defines", is, debug, {}, paths, output);
     }
 
   // Handle empty files
diff --git a/src/macro/Driver.hh b/src/macro/Driver.hh
index 180803ffea2003dbd7823473ca67fab55e2956d6..7bf9765559fa4116702e9489bb25e80271037f95 100644
--- a/src/macro/Driver.hh
+++ b/src/macro/Driver.hh
@@ -84,10 +84,12 @@ namespace macro
       }
     };
 
-    //! Starts parsing a file, returns output in out
-    void parse(const string &file_arg, const string &basename_arg, istream &modfile,
-               ostream &output, bool debug, const vector<pair<string, string>> &defines,
-               vector<filesystem::path> &paths_arg);
+    //! Starts parsing a file, modifies `paths` and `output`
+    //! Both `paths` and `output` are passed as reference
+    //! as they are modified by various macro directives
+    void parse(const string &file, const string &basename, const istream &modfile,
+               bool debug, const vector<pair<string, string>> &defines,
+               vector<filesystem::path> &paths, ostream &output);
 
     //! Name of main file being parsed
     string file;