split some logic into runcmd