Better aggregation support

Added support and tests for aggregation operations.
Ok, I'll reformat the commits to our spec and push again.