backported fix for #512 to master
Merge pull request #518 from nelenkov/master

backported fix for #512 to master