clean up and fix unclosed tags in templates