Refactored to use AngularJS