templates handling code moved to template.cxx