Refactor with linked list