Added logic to flatten out group memberships.