optimized generate