Stop working if cannot get out of loop