network state check and reconnection code updated