Refactoring of the angularjs app