Reorganized runcmd to have a runcmd, check_cmd fcn