added retries, timeouts and some other code changing