fix a bug in aggregation script