fix for #184 based on andyhelp's pull request