Fix for issues 1411 and 1624

These commits fix issues 1624 and 1411

I've posted the patches in the bugtrack, and people are using them with great success. So far, I have no reported issues from these changes.