Thanks for reporting the bug. I installed the attached, which is a conservative patch that should fix the bug, though it doesn't address the more-general issues that you mentioned.