Final fix which should now pass all tests.