Rebase of #2711

Rebase of #2711