Add retries when encountering API errors. Fix for issue #5.