Cherry-picked from 5 commits, from PR's #3654 and #3670: (cherry picked from commit 3df8af7f) (cherry picked from commit 8cad356a) (cherry picked from commit 2ef0aa42) (cherry picked from commit 59b50c82) (cherry picked from commit 00be986f)