Refactor linkedlist cycle