Refactoring to support unit tests.