cleaned up handling of grouped and ungrouped data