wrote basic do_exec() function