Fixes from v1.6.x

This brings the changes from #1014 onto master.