fix a minor bug on template() function