fix bugs about disconnect and handle some exceptions