(bug #3622) rewrite a lot of basketgrouping