Add safety check to limit depth