added recursion detection