loop detection working