Big refactoring of service code