Move build_query into its own object