Add safety against infinte loops