Adding some cherry-picked changes from MAster to 1.6.x