Complete fix for #642
Merge pull request #648 from MrTool/patch-1

Complete fix for #642.