added templates and some logic