Refactored to some real AngularJS