Refactor aggregates module