Copied from master branch.