some refactoring and cleaning, those big methods still need to be split up
generate()