Cherry picked fixes from 1.70 and 1.80