Add timer for connection retries and improve exception handling.