fix bug in connection code