Working on the generation algorithm.