Refactor for better dependancy-injection