Added templates and some logic