more refactoring on the generator - much neater, easier to read, and with less pointless passing around of variables