Add query-structuring code