refactored generator