refactored to work properly with test groups and others