Modified to add sub groups related functionality