cleaner connection code for multi clients, fix crashes