fixed some bugs Involves connection event