refactor template js