extracted code to get the numbers of generations as a clean-up.