refactor template and type