rewrite the service to make it more readable and maintainable