some refactoring, made a method for re-establishing a connection if the connection drops or you can't connect.