refactored angular code