Speedup template lookup
Fix 'stack level too deep' in TemplateError