Refactoring for unit testing.