Numerous fixes. Also pulls in issue #21422.