Refactor command parsing and autocompletion