improved cycle-checking