Preparing the data for aggregation