WIP: Aggregation performance improvements
For Denis' aggregation test case, the changes in this branch brought run time down from about 30 hours to under 40 minutes. Paolo should look over the changes and test this code against the original to make sure no unexpected differences have been introduced.