Optimized some generation code