Squash and cherry-pick PR #4811 #4731

#4731 

See also #4811