Thanks Tim Graham for review and Tai Lee for the additional test to prove this was a regression in 1.6. Backport of 7f2485b4 and 81372159 from master