loop detection