working aggregation script