detect loop in the list