Manually transplanted changes from for_third_party into master branch.