Refactored checkGroup method.