refactoring the services code