refactoring in generator