FIX:max_thread_num's problem and other small changes