optimize the insertTempl function