Refactoring the handling of grouping API to support the handling of more
than one group calculation for streams.