rewrote the disconnect function