Principle looks good, but your patch is weird. It actually reverts the last couple of changes that I and others made. So you somehow made a patch to the current code instead of the code you originally worked with or so.
Could you try to re-do the patch? Otherwise I'm going to have to manually copy bits of code out of your patch ;-)