refactoring to add unit tests