Detect loop and delete it