Refactored to allow use as an import.