Fix threading issues.