Added more cases for grouping data