Fix integer overflow problem in the date computation.

Also, add a backoff + retry strategy for queries.