refactored service code