Port changes from 1.7.x.