Fix for issue #1931

All comments for this patch are in the mentioned bug report. Perhaps I shouldn't submit that issue but at that moment I didn't know how github works (and probably still don't know).

Also now I think I had to commit my changes to branch incoming but this was not evident from "Please make your pull request to incoming, not master". :) So, I made a pull request to incoming but my changes is on master. If I did it wrong I'll redo it.