reorder query pieces