WIP: rebase of #3117

WIP: rebase of #3117