Detecting loop in singly linked list