Merge changes from 4.0, plus some fixes. Poor repo practice.