refactored code to using angular