Fix stitching together all the various query parts