added templates and exception handling