Managed to refactor the code to make it easier to test using dependency injection principles.