Fixed queryFailed function