fix some bugs when connecting