implementing the query