Back porting from 3.3.x (#4899 mainly)