improved command detection