Extracted from upstream repo.