Bugfixes to aggregation