better and simpler array recursion detection