Various threading optimizations