Merged in comments 59-61 from #3134, plus other changes; all merges for 1.40 should be done now; closes #3134