Refactoring to a more testeable version