fix use of range() so that retry_times is actually reached