Backport most of 1.6 changes