Changes made -- further tests required before I'm 100% sure this is fixed.
fixed #10