optimize service layer code