Fixed querying function

Fixed querying function