I'm including the fixed patch (hand edited with a test, the test severely needs review, thanks