various threading improvements