Fix threading issue