Backport bugfixes
Merge branch '4.0'