Refactoring service code