refactored setQuery method