working linked list solution