Adding retry logic

This turned out to be a bigger change than I had anticipated since
retrying forces us to be more specific about the type of errors that
we need  to handle.