refactored to double as an installable library.