Refactoring of Language.detect