Clean up nextGeneration function.