refactors nextGeneration method to get rid of an unnecessary loop