Backport previous commit for 3.4 and 3.6