Cherry pick upstreamable changes from master to mer-3.1