Fix a looping bug in the new occur-check code