backport changes from 1.7  into 1.6.4