Refactored the generator