Aggregates

I still need to add tests, so this code isn't quite ready to merge, but all the functionality should be there...