Refactored angular code