Backport fixes

backport #4094, #4051, #4124, #4020 to 1.7.x