refactor template instantiation