Fixed threading problem