refactor tamplate