move some logic out of get_remote_command to more general call get_command.