breaking run_thread into its own function