Parse groups with more than one record correctly

 - Move to using groupByValue function rather than flatten
 - needs some looking at aggregations that are not sums