Backport of #152 fix for 3.x branch

Applicable to #249