Backport of all changes from master branch to this point.