Index: src/GenPoly/Specialize.h
===================================================================
--- src/GenPoly/Specialize.h	(revision ffec1bfd5e6f76604c43a28508c5ddcc64bd3218)
+++ src/GenPoly/Specialize.h	(revision 5cf1228fbb704ea7ccef879b4c60f16486335b9a)
@@ -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 ffec1bfd5e6f76604c43a28508c5ddcc64bd3218)
+++ src/GenPoly/SpecializeNew.cpp	(revision 5cf1228fbb704ea7ccef879b4c60f16486335b9a)
@@ -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() ) {
Index: src/ResolvExpr/Resolver.cc
===================================================================
--- src/ResolvExpr/Resolver.cc	(revision ffec1bfd5e6f76604c43a28508c5ddcc64bd3218)
+++ src/ResolvExpr/Resolver.cc	(revision 5cf1228fbb704ea7ccef879b4c60f16486335b9a)
@@ -1542,5 +1542,4 @@
 	}
 
-
 	const ast::StaticAssertDecl * Resolver_new::previsit(
 		const ast::StaticAssertDecl * assertDecl
@@ -1554,11 +1553,9 @@
 	const PtrType * handlePtrType( const PtrType * type, const ResolveContext & context ) {
 		if ( type->dimension ) {
-			ast::ptr< ast::Type > sizeType = context.global.sizeType;
+			const ast::Type * sizeType = context.global.sizeType.get();
 			ast::ptr< ast::Expr > dimension = findSingleExpression( type->dimension, sizeType, context );
 			assertf(dimension->env->empty(), "array dimension expr has nonempty env");
 			dimension.get_and_mutate()->env = nullptr;
-			ast::mutate_field(
-				type, &PtrType::dimension,
-				dimension);
+			ast::mutate_field( type, &PtrType::dimension, dimension );
 		}
 		return type;
Index: src/main.cc
===================================================================
--- src/main.cc	(revision ffec1bfd5e6f76604c43a28508c5ddcc64bd3218)
+++ src/main.cc	(revision 5cf1228fbb704ea7ccef879b4c60f16486335b9a)
@@ -439,6 +439,7 @@
 			PASS( "Translate Tries", ControlStruct::translateTries( transUnit ) );
 			PASS( "Gen Waitfor", Concurrency::generateWaitFor( transUnit ) );
-			PASS( "Convert Specializations",  GenPoly::convertSpecializations( transUnit ) ); // needs to happen before tuple types are expanded
-
+
+			// Needs to happen before tuple types are expanded.
+			PASS( "Convert Specializations",  GenPoly::convertSpecializations( transUnit ) );
 
 			translationUnit = convert( move( transUnit ) );
@@ -516,9 +517,5 @@
 			PASS( "Gen Waitfor", Concurrency::generateWaitFor( translationUnit ) );
 			PASS( "Convert Specializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
-
 		}
-
-
-		// PASS( "Convert Specializations",  GenPoly::convertSpecializations( translationUnit ) ); // needs to happen before tuple types are expanded
 
 		PASS( "Expand Tuples", Tuples::expandTuples( translationUnit ) ); // xxx - is this the right place for this?
