Patches from Dan - these DO NOT fix the problem in my pull request..