unit testing and code refactoring