Fix a lot of bugs and change the API of InputToCommand