Threads optimization