error handling and refactoring in service and client