Refactored validation for linked list