detecting cycles