refactoring singly linked list