Several more fixes to these templates and the files they generate.

Converting the AST is still a WIP, but I think the templates are correct
now.