Code refactoring to accommodate unit tests