change logic in displayNamesInGroup and add some unit tests