Backport fix for issue #37 from master