Index: src/AST/Decl.cpp
===================================================================
--- src/AST/Decl.cpp	(revision 2da12ae2df22a8ab193e99e082199971510f6663)
+++ src/AST/Decl.cpp	(revision 2174191456aa4c76295081b7d612c0840239d69f)
@@ -20,5 +20,4 @@
 #include <unordered_map>
 
-#include "CodeGen/FixMain.h"   // for FixMain
 #include "Common/Eval.h"       // for eval
 
@@ -76,10 +75,4 @@
 	}
 	this->type = ftype;
-	// Hack forcing the function "main" to have Cforall linkage to replace
-	// main even if it is inside an extern "C", and also makes sure the
-	// replacing function is always a C function.
-	if ( name == "main" ) {
-		this->linkage = CodeGen::FixMain::getMainLinkage();
-	}
 }
 
@@ -108,8 +101,4 @@
 	}
 	this->type = type;
-	// See note above about this hack.
-	if ( name == "main" ) {
-		this->linkage = CodeGen::FixMain::getMainLinkage();
-	}
 }
 
Index: src/AST/Type.hpp
===================================================================
--- src/AST/Type.hpp	(revision 2da12ae2df22a8ab193e99e082199971510f6663)
+++ src/AST/Type.hpp	(revision 2174191456aa4c76295081b7d612c0840239d69f)
@@ -34,6 +34,4 @@
 
 namespace ast {
-
-template< typename T > class Pass;
 
 class Type : public Node {
Index: src/CodeGen/FixMain.cc
===================================================================
--- src/CodeGen/FixMain.cc	(revision 2da12ae2df22a8ab193e99e082199971510f6663)
+++ src/CodeGen/FixMain.cc	(revision 2174191456aa4c76295081b7d612c0840239d69f)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// FixMain.cc --
+// FixMain.cc -- Tools to change a Cforall main into a C main.
 //
 // Author           : Thierry Delisle
@@ -33,9 +33,9 @@
 namespace {
 
-struct FindMainCore_new {
+struct FindMainCore final {
 	ast::FunctionDecl const * main_declaration = nullptr;
 
 	void previsit( ast::FunctionDecl const * decl ) {
-		if ( FixMain::isMain( decl ) ) {
+		if ( isMain( decl ) ) {
 			if ( main_declaration ) {
 				SemanticError( decl, "Multiple definition of main routine\n" );
@@ -106,7 +106,17 @@
 }
 
+struct FixLinkageCore final {
+	ast::Linkage::Spec const spec;
+	FixLinkageCore( ast::Linkage::Spec spec ) : spec( spec ) {}
+
+	ast::FunctionDecl const * previsit( ast::FunctionDecl const * decl ) {
+		if ( decl->name != "main" ) return decl;
+		return ast::mutate_field( decl, &ast::FunctionDecl::linkage, spec );
+	}
+};
+
 } // namespace
 
-bool FixMain::isMain( const ast::FunctionDecl * decl ) {
+bool isMain( const ast::FunctionDecl * decl ) {
 	if ( std::string("main") != decl->name ) {
 		return false;
@@ -115,8 +125,15 @@
 }
 
-void FixMain::fix( ast::TranslationUnit & translationUnit,
+void fixMainLinkage( ast::TranslationUnit & translationUnit,
+		bool replace_main ) {
+	ast::Linkage::Spec const spec =
+		( replace_main ) ? ast::Linkage::Cforall : ast::Linkage::C;
+	ast::Pass<FixLinkageCore>::run( translationUnit, spec );
+}
+
+void fixMainInvoke( ast::TranslationUnit & translationUnit,
 		std::ostream &os, const char * bootloader_filename ) {
 
-	ast::Pass<FindMainCore_new> main_finder;
+	ast::Pass<FindMainCore> main_finder;
 	ast::accept_all( translationUnit, main_finder );
 	if ( nullptr == main_finder.core.main_declaration ) return;
Index: src/CodeGen/FixMain.h
===================================================================
--- src/CodeGen/FixMain.h	(revision 2da12ae2df22a8ab193e99e082199971510f6663)
+++ src/CodeGen/FixMain.h	(revision 2174191456aa4c76295081b7d612c0840239d69f)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// FixMain.h -- 
+// FixMain.h -- Tools to change a Cforall main into a C main.
 //
 // Author           : Thierry Delisle
@@ -17,8 +17,4 @@
 
 #include <iosfwd>
-#include <memory>
-#include <list>
-
-#include "AST/LinkageSpec.hpp"
 
 namespace ast {
@@ -29,22 +25,13 @@
 namespace CodeGen {
 
-class FixMain {
-public :
-	static inline ast::Linkage::Spec getMainLinkage() {
-		return replace_main ? ast::Linkage::Cforall : ast::Linkage::C;
-	}
+/// Is this function a program main function?
+bool isMain( const ast::FunctionDecl * decl );
 
-	static inline void setReplaceMain(bool val) {
-		replace_main = val;
-	}
+/// Adjust the linkage of main functions.
+void fixMainLinkage( ast::TranslationUnit & transUnit, bool replaceMain );
 
-	static bool isMain(const ast::FunctionDecl * decl);
-
-	static void fix( ast::TranslationUnit & translationUnit,
-			std::ostream &os, const char * bootloader_filename );
-
-private:
-	static bool replace_main;
-};
+/// Add a wrapper around to run the Cforall main.
+void fixMainInvoke( ast::TranslationUnit & transUnit,
+		std::ostream & os, const char * bootloaderFilename );
 
 } // namespace CodeGen
Index: c/CodeGen/FixMain2.cc
===================================================================
--- src/CodeGen/FixMain2.cc	(revision 2da12ae2df22a8ab193e99e082199971510f6663)
+++ 	(revision )
@@ -1,28 +1,0 @@
-//
-// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
-//
-// The contents of this file are covered under the licence agreement in the
-// file "LICENCE" distributed with Cforall.
-//
-// FixMain2.cc -- A side file used to seperate the compiler and demangler.
-//
-// Author           : Andrew Beach
-// Created On       : Tue May 17 10:05:00 2022
-// Last Modified By : Andrew Beach
-// Last Modified On : Tue May 17 10:08:00 2022
-// Update Count     : 0
-//
-
-#include "FixMain.h"
-
-namespace CodeGen {
-
-bool FixMain::replace_main = false;
-
-} // namespace CodeGen
-
-// Local Variables: //
-// tab-width: 4 //
-// mode: c++ //
-// compile-command: "make install" //
-// End: //
Index: src/CodeGen/FixNames.cc
===================================================================
--- src/CodeGen/FixNames.cc	(revision 2da12ae2df22a8ab193e99e082199971510f6663)
+++ src/CodeGen/FixNames.cc	(revision 2174191456aa4c76295081b7d612c0840239d69f)
@@ -28,6 +28,9 @@
 
 namespace CodeGen {
+
+namespace {
+
 /// Does work with the main function and scopeLevels.
-class FixNames_new final {
+class FixNames final {
 	int scopeLevel = 1;
 
@@ -45,5 +48,5 @@
 
 	const ast::FunctionDecl *postvisit( const ast::FunctionDecl *functionDecl ) {
-		if ( FixMain::isMain( functionDecl ) ) {
+		if ( isMain( functionDecl ) ) {
 			auto mutDecl = ast::mutate( functionDecl );
 
@@ -80,6 +83,8 @@
 };
 
+} // namespace
+
 void fixNames( ast::TranslationUnit & translationUnit ) {
-	ast::Pass<FixNames_new>::run( translationUnit );
+	ast::Pass<FixNames>::run( translationUnit );
 }
 
Index: src/CodeGen/FixNames.h
===================================================================
--- src/CodeGen/FixNames.h	(revision 2da12ae2df22a8ab193e99e082199971510f6663)
+++ src/CodeGen/FixNames.h	(revision 2174191456aa4c76295081b7d612c0840239d69f)
@@ -16,7 +16,4 @@
 #pragma once
 
-#include <list>  // for list
-
-class Declaration;
 namespace ast {
 	class TranslationUnit;
@@ -24,8 +21,8 @@
 
 namespace CodeGen {
-	/// mangles object and function names
-	void fixNames( std::list< Declaration* > & translationUnit );
+
 /// Sets scope levels and fills in main's default return.
 void fixNames( ast::TranslationUnit & translationUnit );
+
 } // namespace CodeGen
 
Index: src/CodeGen/module.mk
===================================================================
--- src/CodeGen/module.mk	(revision 2da12ae2df22a8ab193e99e082199971510f6663)
+++ src/CodeGen/module.mk	(revision 2174191456aa4c76295081b7d612c0840239d69f)
@@ -18,6 +18,4 @@
 	CodeGen/CodeGeneratorNew.cpp \
 	CodeGen/CodeGeneratorNew.hpp \
-	CodeGen/FixMain2.cc \
-	CodeGen/FixMain.h \
 	CodeGen/GenType.cc \
 	CodeGen/GenType.h \
@@ -29,4 +27,5 @@
 	CodeGen/Generate.h \
 	CodeGen/FixMain.cc \
+	CodeGen/FixMain.h \
 	CodeGen/FixNames.cc \
 	CodeGen/FixNames.h \
Index: src/main.cc
===================================================================
--- src/main.cc	(revision 2da12ae2df22a8ab193e99e082199971510f6663)
+++ src/main.cc	(revision 2174191456aa4c76295081b7d612c0840239d69f)
@@ -250,5 +250,4 @@
 
 	parse_cmdline( argc, argv );						// process command-line arguments
-	CodeGen::FixMain::setReplaceMain( !nomainp );
 
 	if ( waiting_for_gdb ) {
@@ -394,4 +393,5 @@
 		PASS( "Translate Tries", ControlStruct::translateTries, transUnit );
 		PASS( "Gen Waitfor", Concurrency::generateWaitFor, transUnit );
+		PASS( "Fix Main Linkage", CodeGen::fixMainLinkage, transUnit, !nomainp );
 
 		// Needs to happen before tuple types are expanded.
@@ -421,6 +421,6 @@
 
 		PASS( "Code Gen", CodeGen::generate, transUnit, *output, !genproto, prettycodegenp, true, linemarks, false );
-
-		CodeGen::FixMain::fix( transUnit, *output, (PreludeDirector + "/bootloader.c").c_str() );
+		CodeGen::fixMainInvoke( transUnit, *output, (PreludeDirector + "/bootloader.c").c_str() );
+
 		if ( output != &cout ) {
 			delete output;
