detect loop in list