Fix issue with variable referenced before assignment, update template.