refactored service.js file