Backports more fixes to 1.8

backport gh-4176, gh-4197, gh-4206, gh-4220