code changed to use angularjs