fixed some bugs in connection handling