Added better check for template
Added better check for template