Fixed an important bug in the generating algorithm.