extract the query creation into a BuildQuery method