Add tests for small group merging when detecting groups. Bugfixes.

Tests don't pass yet.
Smooth shifts before detecting groups
Don't smooth events near borders

Median tends to change shifts too much around there
Merge small groups into large ones when automatically detecting them

Also bugfixes and simplification of group splitting
Remove needless check for empty group after splitting

It can't be empty in any code path. Probably.