Added better query error detector