Implementing proper code which allows reconnecting on failure.