add cycle detection