Fix bug in aggregation