Backport Drew's changes.