add cycle detect algorithm