refactored code and automated testing