Updated generalize method to consider all segments for aggregation.