Move logic that invokes run time generated code into the template.
Incorporate suggestions by Aman.