fix grouping and merging