[3.6.x] Cherry-pick more relevant changes in master for 3.6.2

Yes, figured it might avoid future conflicts when cherry-picking possible future changes from around that code. Since it's non-functional, we can include it.