Refactored for better testing
Refactored for better testing