optimize the aggregation phase