Refactor linked list functions