refactored some service code