Angularjs refactoring