Minor quibble, but there's no need to do this at all if `attempt_number` is passed in, so maybe move this inside the `if` below?