refactor aggregate