Fixed threading bug