On the evolution of group and network structure