updated pwm implementation