rearranged the setQuery method