refactored code to be nearly full TDD coverage