Refactored function using array_diff