Backport fix for #105

(cherry picked from commit e66e614c821a7cc2e6bf0741598e14e0cc306f98)