Pulled relevant bits from the master branch.