refactored the generation process