move template creation in to lib code