Add changes from upstream d40af7d