Merging v1.7.x on to master

This PR merges the latest 1.7.x bugfixes onto master.