Will it ever be the case that `groupnames` is the empty list, and so trying to get the 0th element will result in an `IndexError`? You mentioned the case of none of the names existing, and that made me wonder about other edge cases.