more templating, adding error guards