Update with working changes and working conversion to AngularJS