added better exception handling so the run loop is killed if the connection dies.