Front-ported changes from 6.1.x branch.