Improved command detection