Backport ISPN-3443 and some related fixes + ISPN-3779 to the 5.2.x branch