Two loops are enough. I was confused by the fact that on sandbox app it failed on every third refresh. I will repush it soon.

What do you mean by the second question?