Fixed erroneous check for template query success