fix CMD issues and add history support.