refactored code and added angular.js