Backport of e1f049d65b17bba5fb0bbb76695b653ea37229b9