CLEARWATER: #1199 duplicate for SCTX-1334 (with #1062 duplicate))

Changes to fix SCTX-1334: this is a duplicate of pull-request #1199 and also incorporates a duplicate of pull-request #1062 (for CA-87377) since that has changes which are needed for #1199 to apply cleanly.