Refactoring of group management code

Give groups the same makeover users had a while ago.

Improves testability of groups code, old api is re-implemented on top of the new one.

cc @MTGap @bartv2 @karlitschek @DeepDiver1975