Fixed threading issues in connection.