Backported commits from 1.7.2 version.