update template fitting code