check for cycles