Limit the headphone loudness
When using headphones, having the volume at around 50% is already very loud, and having it higher produces heavy distortion and misdetection of headphone (un)plug events. The loudness should be limited to some reasonable value there.