refactoring main controller factoring out code into two services to make the controller smaller and