Refactor for testing.