refactored code to fit angular