refactored do_command so main dialog uses it