Ported latest changes to 1.7