Index: src/GenPoly/Specialize.h
===================================================================
--- src/GenPoly/Specialize.h	(revision 4c48be0244175628306b8fa1224cf2acb1666dab)
+++ src/GenPoly/Specialize.h	(revision dd33c1f4ee8e23b2956d02571e0614fdf0a438d4)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// Specialize.h -- 
+// Specialize.h -- Generate thunks to specialize polymorphic functions.
 //
 // Author           : Richard C. Bilson
@@ -17,7 +17,9 @@
 
 #include <list>  // for list
-#include "AST/TranslationUnit.hpp"
 
 class Declaration;
+namespace ast {
+	class TranslationUnit;
+}
 
 namespace GenPoly {
Index: src/GenPoly/SpecializeNew.cpp
===================================================================
--- src/GenPoly/SpecializeNew.cpp	(revision 4c48be0244175628306b8fa1224cf2acb1666dab)
+++ src/GenPoly/SpecializeNew.cpp	(revision dd33c1f4ee8e23b2956d02571e0614fdf0a438d4)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// SpecializeNew.cpp --
+// SpecializeNew.cpp -- Generate thunks to specialize polymorphic functions.
 //
 // Author           : Andrew Beach
@@ -201,9 +201,4 @@
 			*formal, *actual, getInferredParams( expr ) );
 	}
-	//for ( auto pair : group_iterate( formal->params, mut->args ) ) {
-	//	const ast::ptr<ast::Type> & formal = std::get<0>( pair );
-	//	ast::ptr<ast::Expr> & actual = std::get<1>( pair );
-	//	*actual = doSpecialization( (*actual)->location, *formal, *actual, getInferredParams( expr ) );
-	//}
 	return mut;
 }
@@ -227,27 +222,11 @@
 }
 
-// Restructures the arguments to match the structure of the formal parameters
-// of the actual function. [begin, end) are the exploded arguments.
-template<typename Iterator, typename OutIterator>
-void structureArg( const CodeLocation & location, const ast::Type * type,
-		Iterator & begin, Iterator end, OutIterator out ) {
-	if ( auto tuple = dynamic_cast<const ast::TupleType *>( type ) ) {
-		std::vector<ast::ptr<ast::Expr>> exprs;
-		for ( const ast::Type * t : *tuple ) {
-			structureArg( location, t, begin, end, std::back_inserter( exprs ) );
-		}
-		*out++ = new ast::TupleExpr( location, std::move( exprs ) );
-	} else {
-		assertf( begin != end, "reached the end of the arguments while structuring" );
-		*out++ = *begin++;
-	}
-}
-
-#if 0
+// Restructures arguments to match the structure of the formal parameters
+// of the actual function. Returns the next structured argument.
 template<typename Iterator>
 const ast::Expr * structureArg(
 		const CodeLocation& location, const ast::ptr<ast::Type> & type,
 		Iterator & begin, const Iterator & end ) {
-	if ( auto tuple = type->as<ast::TupleType>() ) {
+	if ( auto tuple = type.as<ast::TupleType>() ) {
 		std::vector<ast::ptr<ast::Expr>> exprs;
 		for ( const ast::Type * t : *tuple ) {
@@ -260,5 +239,4 @@
 	}
 }
-#endif
 
 namespace {
@@ -291,6 +269,4 @@
 		// Must replace only occurrences of type variables
 		// that occure free in the thunk's type.
-		//ast::TypeSubstitution::ApplyResult<ast::FunctionType>
-		//	typeSubs->applyFree( newType );
 		auto result = typeSubs->applyFree( newType );
 		newType = result.node.release();
@@ -300,21 +276,14 @@
 	using DeclVector = std::vector<ast::ptr<ast::TypeDecl>>;
 
-	//const std::string & thunkName = thunkNamer.newName();
-	//UniqueName paramNamer(thunkName + "Param");
 	UniqueName paramNamer( paramPrefix );
 
-	//auto toParamDecl = [&location, &paramNamer]( const ast::Type * type ) {
-	//	return new ast::ObjectDecl(
-	//		location, paramNamer.newName(), ast::deepCopy( type ) );
-	//};
-
 	// Create new thunk with same signature as formal type.
-
-	// std::map<const ast::TypeDecl *, std::pair<int, int>> typeMap;
 	ast::Pass<TypeInstFixer> fixer;
 	for (const auto & kv : newType->forall) {
 		if (fixer.core.typeMap.count(kv->base)) {
-			std::cerr << location << ' ' << kv->base->name << ' ' << kv->expr_id << '_' << kv->formal_usage << ',' 
-			<< fixer.core.typeMap[kv->base].first << '_' << fixer.core.typeMap[kv->base].second << std::endl;
+			std::cerr << location << ' ' << kv->base->name
+				<< ' ' << kv->expr_id << '_' << kv->formal_usage
+				<< ',' << fixer.core.typeMap[kv->base].first
+				<< '_' << fixer.core.typeMap[kv->base].second << std::endl;
 			assertf(false, "multiple formals in specialize");
 		}
@@ -322,5 +291,5 @@
 			fixer.core.typeMap[kv->base] = std::make_pair(kv->expr_id, kv->formal_usage);
 		}
-	} 
+	}
 
 	ast::CompoundStmt * thunkBody = new ast::CompoundStmt( location );
@@ -345,8 +314,5 @@
 		);
 
-	// thunkFunc->accept(fixer);
 	thunkFunc->fixUniqueId();
-
-
 
 	// Thunks may be generated and not used, avoid them.
@@ -375,8 +341,5 @@
 		// Name each thunk parameter and explode it.
 		// These are then threaded back into the actual function call.
-		//param->name = paramNamer.newName();
 		ast::DeclWithType * mutParam = ast::mutate( param.get() );
-		// - Should be renamed earlier. -
-		//mutParam->name = paramNamer.newName();
 		explodeSimple( location, new ast::VariableExpr( location, mutParam ),
 			std::back_inserter( args ) );
@@ -388,6 +351,6 @@
 		argBegin = args.begin(), argEnd = args.end();
 	for ( const auto & actualArg : actualType->params ) {
-		structureArg( location, actualArg.get(), argBegin, argEnd,
-			std::back_inserter( app->args ) );
+		app->args.push_back(
+			structureArg( location, actualArg.get(), argBegin, argEnd ) );
 	}
 	assertf( argBegin == argEnd, "Did not structure all arguments." );
@@ -469,10 +432,9 @@
 	// Create thunks for the inferred parameters.
 	// This is not needed for intrinsic calls, because they aren't
-	// actually passed
-	//
-	// need to handle explicit params before inferred params so that
-	// explicit params do not recieve a changed set of inferParams (and
-	// change them again) alternatively, if order starts to matter then
-	// copy appExpr's inferParams and pass them to handleExplicitParams.
+	// actually passed to the function. It needs to handle explicit params
+	// before inferred params so that explicit params do not recieve a
+	// changed set of inferParams (and change them again).
+	// Alternatively, if order starts to matter then copy expr's inferParams
+	// and pass them to handleExplicitParams.
 	ast::ApplicationExpr * mut = handleExplicitParams( expr );
 	if ( !mut->inferred.hasParams() ) {
