Refactored destroy_list function from linked list module.