Added better handling of QueryFailure flag