Complete backporting of #407 for 2.3.3