backport of commit d57df01c518e371520ff3581c4c2aa724ef5aae9