Refactor template visit & Add template test