Split aggregation and filtering functions apart