Backports from upstream.
Backport of patches from upstream.