Implemented data grouping routine.