Detect loop in list