Clean up JS code for AngularJS