refactored angular code for readability and simplicity