Partial back-port of c2d96d14 [ci skip]

[Juanito Fatas + Robin Dupret]