Mange groups and minor refactoring