Updated PWM functions for proper functionality