reapply my fix for PR8961 with a tweak to properly handle