Added detectLanguage function