refactoring to try and implement cleaner dependency injection.
tidy