corrected generation logic