changed next_thread_to_run but it needs fixed