Ported last 3.4 changes to 3.5 branch.