Improved command handling