Fixed threading issues