Backports for 1.9.1

backports of gh-4982 and gh-5186