completed aggregate.py