Fix threading bottleneck