fixed loop detection