corrected max depth safety check for cycles