Fix query integrity