fix query lgoic