made a few tweaks to template_tools.h