move run_loop, move loop from main into run_loop