new runcmd() and improved organization