Adding aggregateByAType function