refactor into a service