Bug fixes; more reliable PWM transition detection