generator refactored into a class