Backport fixes from 1.7.10.