Adding automatic groups selection algorithm