Refactoring angularjs