Some threading fixes