Refactor pwm operations