Refactored for testing