Final version of the aggregation algorithm.