Merge my pull request #3489, then rebase this PR.