fixed bug in template code, it now handles nonexistent templates