ported from private repo.