working PWM and cleanup