Refactor to AngularJS