Refactor to use angularjs part 2