Added data aggregation code