refactored sorting and filtering logic for the customers