angularjs refactoring