Complete rewrite of the generator.