refactored for testing