Enhanced method for language identification (less code and easier to manage)