Backport Joe's commits.