Added better check for template