backport #6199 & #6354 to 2.3.0