The first if is to prevent retries from exceeding the maximum. The second one is for status logic only.