Rebase of #7538

see #7538