Merge fixes backported from 1.x branch