Refactor template init logic