Refactor to angularjs part 1