This is a new implementation of the group handling introduced in #125 The previous implementation failed to preserve provider groups properly. This also adds tests for the behaviour.