Backport of pr #495 to 0.9.x branch

Fixes issue #220