refactored code adn tests all passing.