Fixed template functions

Global variable templates now set in main() to allow clearer ordering of
function application.