Moving retry within entry loop to limit the amount of queries during a retry.