Added code and explanation about the choice of the best N groups.