refactor aggregates a bit to reduce repetitive code