Improve command handling