refactored everything into a clean, readable, well-commented asynchronous module