Backport of #8183 and #8197

Backport of #8183 and #8197

Litmus test passes successfully.