Code to aggregate the data