Fix bugs & complete the cmd version