- partial porting of merge 50117f (adapted to 1.9)