refactoring angularjs