Port fix for #239 to master