rewrote run_thread