Bug/threading fixes