SP-677

cherry picking from previous cases to build a complete fix.