Replace retry with break/next in loop to avoid possible infinite loop