templates and code gen fixed