Much improved fix now merged to trunk.