Refactor code to make it easy to do dependency injection