improve error message if template is broken, whitespace cleanup