thread_join function is slightly modefied