Loop detection