debugging grouping function and cleanup