Forward port of #5752 and #5781 into CMSSW_7_3_X.