Adding multithreading support