updated cycle recognition algorithm

should be a better best-case running time