updated code to use templates and included template files