unit testing and refactoring