added exit handling to prevent PWM mess