re-factored templates, added tests