Optimized the pwm generator