This is a rebase of most commits from #14766, resolving conflicts and a few other evaluation problems.