Refactor: move aggregate stuff to aggregate.js