cleaned up code generation for very large templates, still needs
dispatch cleaned up.