Fix circular linked list bug and added detection