improve aggregation script