Add changes from upstream commit 4d5f9b60e3.