Here's the full patch for this, which I mentioned earlier, to give you a feel for what's needed. It's tedious, but is pretty straightforward. I'll test it more before committing.