The changes in this method are the meat of this PR.