Multithreading code is introduced (doesn't work properly now).