This is an updated version of the patch I sent earlier, now with the reformatting changes requested by John. Apparently my previous resend somehow got lost (as I did not use git send-email?).