Added lost connection handler and stability counter