refactored to Angular.js