first half of groupBy