I wrote this patch the same day I filed the bug. I figured this was a good start, but I'm not sold on it or anything.