Cherry pick from legacy.