Added better exception handling to retry if unable to connect