Refactoring to support testing