off-by-one fix for retry counting
minor error handling improvement