Abstracted templating, adding error handling