Cleanup of aggregation handling. Fixes #1308