Porting of #3580 to support