Changed the scope of all those variables in generate()