Improve command existence checking logic