implement recursion detection