Fix bug in new_generation function