Backport fix for #38 and #39 from 1.3