Refactor the template