fixed incorrect query state handling