refactored the angular code, created a service