refactoring the generator