Optimized for multithreading