fixed issue #39 in upstream master