Started refactoring and separating code from the app controller