Pull 2699 rebased

Rebase #2699.