diff --git a/daemon/src/audio/alsa/alsalayer.cpp b/daemon/src/audio/alsa/alsalayer.cpp
index 56b1ae2a4cc285451f86690a485addbe0370ffc6..c3416825413e4947bda9b67b60c4997e85463508 100644
--- a/daemon/src/audio/alsa/alsalayer.cpp
+++ b/daemon/src/audio/alsa/alsalayer.cpp
@@ -51,11 +51,11 @@ class AlsaThread : public ost::Thread
         AlsaThread (const AlsaThread& at);
         AlsaThread& operator= (const AlsaThread& at);
 
-        AlsaLayer* _alsa;
+        AlsaLayer* alsa_;
 };
 
 AlsaThread::AlsaThread (AlsaLayer *alsa)
-    : Thread(), _alsa (alsa)
+    : Thread(), alsa_(alsa)
 {
     setCancel (cancelDeferred);
 }
@@ -66,7 +66,7 @@ AlsaThread::AlsaThread (AlsaLayer *alsa)
 void AlsaThread::run (void)
 {
     while (!testCancel()) {
-        _alsa->audioCallback();
+        alsa_->audioCallback();
         Thread::sleep (20);
     }
 }
@@ -481,21 +481,21 @@ AlsaLayer::getSoundCardsInfo (int stream)
 
 
 bool
-AlsaLayer::soundCardIndexExist (int card, int stream)
+AlsaLayer::soundCardIndexExists(int card, int stream)
 {
     snd_ctl_t* handle;
     snd_pcm_info_t *pcminfo;
-    snd_pcm_info_alloca (&pcminfo);
-    std::string name = "hw:";
+    snd_pcm_info_alloca(&pcminfo);
+    std::string name("hw:");
     std::stringstream ss;
-    ss << card ;
-    name.append (ss.str());
+    ss << card;
+    name.append(ss.str());
 
-    if (snd_ctl_open (&handle, name.c_str(), 0) != 0)
+    if (snd_ctl_open(&handle, name.c_str(), 0) != 0)
 		return false;
 
-    snd_pcm_info_set_stream (pcminfo , (stream == SFL_PCM_PLAYBACK) ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE);
-	bool ret = snd_ctl_pcm_info (handle , pcminfo) >= 0;
+    snd_pcm_info_set_stream(pcminfo , (stream == SFL_PCM_PLAYBACK) ? SND_PCM_STREAM_PLAYBACK : SND_PCM_STREAM_CAPTURE);
+	bool ret = snd_ctl_pcm_info(handle , pcminfo) >= 0;
 	snd_ctl_close(handle);
 	return ret;
 }
diff --git a/daemon/src/audio/alsa/alsalayer.h b/daemon/src/audio/alsa/alsalayer.h
index a406667a0075926c1fdb9a05a0bb68cba05e5a70..ed2febb2b86e0163b3b0f0c08b776fdcba1a7c92 100644
--- a/daemon/src/audio/alsa/alsalayer.h
+++ b/daemon/src/audio/alsa/alsalayer.h
@@ -102,7 +102,7 @@ class AlsaLayer : public AudioLayer
          * @return bool True if it exists and supports the mode
          *		    false otherwise
          */
-        static bool soundCardIndexExist (int card , int stream);
+        static bool soundCardIndexExists(int card, int stream);
 
         /**
          * An index is associated with its string description
diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp
index 094fdb9fb2e42524f8b2aa547d736cf5527bb747..f41b083cdf12e4bc8ea491c86c7aa5bfb326f3fc 100644
--- a/daemon/src/managerimpl.cpp
+++ b/daemon/src/managerimpl.cpp
@@ -1993,7 +1993,7 @@ void ManagerImpl::setAudioPlugin (const std::string& audioPlugin)
 
     // Recreate audio driver with new settings
     delete _audiodriver;
-    _audiodriver = preferences.createAudioLayer();
+    _audiodriver = audioPreference.createAudioLayer();
     if (wasStarted)
         _audiodriver->startStream();
 
@@ -2032,7 +2032,7 @@ void ManagerImpl::setAudioDevice (const int index, int streamType)
 
     // Recreate audio driver with new settings
     delete _audiodriver;
-    _audiodriver = preferences.createAudioLayer();
+    _audiodriver = audioPreference.createAudioLayer();
 
     if (wasStarted)
         _audiodriver->startStream();
@@ -2271,7 +2271,7 @@ void ManagerImpl::setAudioManager (const std::string &api)
         return;
     }
 
-    if (api == preferences.getAudioApi()) {
+    if (api == audioPreference.getAudioApi()) {
         _debug ("Manager: Audio manager chosen already in use. No changes made. ");
         audioLayerMutexUnlock();
         return;
@@ -2286,7 +2286,7 @@ void ManagerImpl::setAudioManager (const std::string &api)
 
 std::string ManagerImpl::getAudioManager (void) const
 {
-    return preferences.getAudioApi();
+    return audioPreference.getAudioApi();
 }
 
 
@@ -2364,31 +2364,7 @@ void ManagerImpl::setEchoCancelDelay(int delay)
 void ManagerImpl::initAudioDriver (void)
 {
     audioLayerMutexLock();
-
-    /* Retrieve the global devices info from the user config */
-    int numCardIn = audioPreference.getCardin();
-    int numCardOut = audioPreference.getCardout();
-    int numCardRing = audioPreference.getCardring();
-
-    if (!AlsaLayer::soundCardIndexExist (numCardIn, SFL_PCM_CAPTURE)) {
-        _debug (" Card with index %d doesn't exist or cannot capture. Switch to 0.", numCardIn);
-        numCardIn = ALSA_DFT_CARD_ID;
-        audioPreference.setCardin (ALSA_DFT_CARD_ID);
-    }
-
-    if (!AlsaLayer::soundCardIndexExist (numCardOut, SFL_PCM_PLAYBACK)) {
-        _debug (" Card with index %d doesn't exist or cannot playback. Switch to 0.", numCardOut);
-        numCardOut = ALSA_DFT_CARD_ID;
-        audioPreference.setCardout (ALSA_DFT_CARD_ID);
-    }
-
-    if (!AlsaLayer::soundCardIndexExist (numCardRing, SFL_PCM_RINGTONE)) {
-        _debug (" Card with index %d doesn't exist or cannot ringtone. Switch to 0.", numCardRing);
-        numCardRing = ALSA_DFT_CARD_ID;
-        audioPreference.setCardring (ALSA_DFT_CARD_ID);
-    }
-
-    _audiodriver = preferences.createAudioLayer();
+    _audiodriver = audioPreference.createAudioLayer();
 
     audioLayerMutexUnlock();
 }
@@ -2400,7 +2376,7 @@ void ManagerImpl::switchAudioManager (void)
     bool wasStarted = _audiodriver->isStarted();
     delete _audiodriver;
 
-    _audiodriver = preferences.switchAndCreateAudioLayer();
+    _audiodriver = audioPreference.switchAndCreateAudioLayer();
 
     if (wasStarted)
         _audiodriver->startStream();
@@ -2433,7 +2409,7 @@ void ManagerImpl::audioSamplingRateChanged (int samplerate)
     _mainBuffer.setInternalSamplingRate(samplerate);
 
     delete _audiodriver;
-    _audiodriver = preferences.createAudioLayer();
+    _audiodriver = audioPreference.createAudioLayer();
 
     unsigned int sampleRate = _audiodriver->getSampleRate();
 
diff --git a/daemon/src/preferences.cpp b/daemon/src/preferences.cpp
index f0f80a57156259a118c4b3f7687e78d0d9495981..359e28dd499b7b14577d4e59e2d1c41895e33005 100644
--- a/daemon/src/preferences.cpp
+++ b/daemon/src/preferences.cpp
@@ -45,300 +45,310 @@ namespace {
     static const char * const DFT_VOL_MICRO_STR	= "100";    /** Default mic volume */
 } // end anonymous namespace
 
-Preferences::Preferences() :  _accountOrder ("")
-    , _audioApi (PULSEAUDIO_API_STR)
-    , _historyLimit (30)
-    , _historyMaxCalls (20)
-    , _notifyMails (false)
-    , _zoneToneChoice (DFT_ZONE) // DFT_ZONE
-    , _registrationExpire (180)
-    , _portNum (5060)
-    , _searchBarDisplay (true)
-    , _zeroConfenable (false)
-    , _md5Hash (false)
+Preferences::Preferences() :  _accountOrder("")
+    , _historyLimit(30)
+    , _historyMaxCalls(20)
+    , _notifyMails(false)
+    , _zoneToneChoice(DFT_ZONE) // DFT_ZONE
+    , _registrationExpire(180)
+    , _portNum(5060)
+    , _searchBarDisplay(true)
+    , _zeroConfenable(false)
+    , _md5Hash(false)
 {
-
-}
-
-AudioLayer* Preferences::createAudioLayer()
-{
-    if (_audioApi == PULSEAUDIO_API_STR and system("ps -C pulseaudio") == 0)
-        return new PulseLayer;
-    else {
-        _audioApi = ALSA_API_STR;
-        return new AlsaLayer;
-    }
-}
-
-AudioLayer* Preferences::switchAndCreateAudioLayer()
-{
-    if (_audioApi == PULSEAUDIO_API_STR)
-        _audioApi = ALSA_API_STR;
-    else
-        _audioApi = PULSEAUDIO_API_STR;
-    return createAudioLayer();
 }
 
-void Preferences::serialize (Conf::YamlEmitter *emiter)
+void Preferences::serialize(Conf::YamlEmitter *emiter)
 {
-	Conf::MappingNode preferencemap (NULL);
+	Conf::MappingNode preferencemap(NULL);
 
-    Conf::ScalarNode order (_accountOrder);
-    Conf::ScalarNode audioapi (_audioApi);
+    Conf::ScalarNode order(_accountOrder);
     std::stringstream histlimitstr;
     histlimitstr << _historyLimit;
-    Conf::ScalarNode historyLimit (histlimitstr.str());
+    Conf::ScalarNode historyLimit(histlimitstr.str());
     std::stringstream histmaxstr;
     histmaxstr << _historyMaxCalls;
-    Conf::ScalarNode historyMaxCalls (histmaxstr.str());
-    Conf::ScalarNode notifyMails (_notifyMails);
-    Conf::ScalarNode zoneToneChoice (_zoneToneChoice);
+    Conf::ScalarNode historyMaxCalls(histmaxstr.str());
+    Conf::ScalarNode notifyMails(_notifyMails);
+    Conf::ScalarNode zoneToneChoice(_zoneToneChoice);
     std::stringstream expirestr;
     expirestr << _registrationExpire;
-    Conf::ScalarNode registrationExpire (expirestr.str());
+    Conf::ScalarNode registrationExpire(expirestr.str());
     std::stringstream portstr;
     portstr << _portNum;
-    Conf::ScalarNode portNum (portstr.str());
-    Conf::ScalarNode searchBarDisplay (_searchBarDisplay);
-    Conf::ScalarNode zeroConfenable (_zeroConfenable);
-    Conf::ScalarNode md5Hash (_md5Hash);
-
-    preferencemap.setKeyValue (orderKey, &order);
-    preferencemap.setKeyValue (audioApiKey, &audioapi);
-    preferencemap.setKeyValue (historyLimitKey, &historyLimit);
-    preferencemap.setKeyValue (historyMaxCallsKey, &historyMaxCalls);
-    preferencemap.setKeyValue (notifyMailsKey, &notifyMails);
-    preferencemap.setKeyValue (zoneToneChoiceKey, &zoneToneChoice);
-    preferencemap.setKeyValue (registrationExpireKey, &registrationExpire);
-    preferencemap.setKeyValue (portNumKey, &portNum);
-    preferencemap.setKeyValue (searchBarDisplayKey, &searchBarDisplay);
-    preferencemap.setKeyValue (zeroConfenableKey, &zeroConfenable);
-    preferencemap.setKeyValue (md5HashKey, &md5Hash);
-
-    emiter->serializePreference (&preferencemap);
+    Conf::ScalarNode portNum(portstr.str());
+    Conf::ScalarNode searchBarDisplay(_searchBarDisplay);
+    Conf::ScalarNode zeroConfenable(_zeroConfenable);
+    Conf::ScalarNode md5Hash(_md5Hash);
+
+    preferencemap.setKeyValue(orderKey, &order);
+    preferencemap.setKeyValue(historyLimitKey, &historyLimit);
+    preferencemap.setKeyValue(historyMaxCallsKey, &historyMaxCalls);
+    preferencemap.setKeyValue(notifyMailsKey, &notifyMails);
+    preferencemap.setKeyValue(zoneToneChoiceKey, &zoneToneChoice);
+    preferencemap.setKeyValue(registrationExpireKey, &registrationExpire);
+    preferencemap.setKeyValue(portNumKey, &portNum);
+    preferencemap.setKeyValue(searchBarDisplayKey, &searchBarDisplay);
+    preferencemap.setKeyValue(zeroConfenableKey, &zeroConfenable);
+    preferencemap.setKeyValue(md5HashKey, &md5Hash);
+
+    emiter->serializePreference(&preferencemap);
 }
 
-void Preferences::unserialize (Conf::MappingNode *map)
+void Preferences::unserialize(Conf::MappingNode *map)
 {
     if (map == NULL) {
-        _error ("Preference: Error: Preference map is NULL");
+        _error("Preference: Error: Preference map is NULL");
         return;
     }
 
-    map->getValue (orderKey, &_accountOrder);
-    map->getValue (audioApiKey, &_audioApi);
-    // 1 is pulseaudio, 0 is alsa
-    map->getValue (historyLimitKey, &_historyLimit);
-    map->getValue (historyMaxCallsKey, &_historyMaxCalls);
-    map->getValue (notifyMailsKey, &_notifyMails);
-    map->getValue (zoneToneChoiceKey, &_zoneToneChoice);
-    map->getValue (registrationExpireKey, &_registrationExpire);
-    map->getValue (portNumKey, &_portNum);
-    map->getValue (searchBarDisplayKey, &_searchBarDisplay);
-    map->getValue (zeroConfenableKey, &_zeroConfenable);
-    map->getValue (md5HashKey, &_md5Hash);
+    map->getValue(orderKey, &_accountOrder);
+    map->getValue(historyLimitKey, &_historyLimit);
+    map->getValue(historyMaxCallsKey, &_historyMaxCalls);
+    map->getValue(notifyMailsKey, &_notifyMails);
+    map->getValue(zoneToneChoiceKey, &_zoneToneChoice);
+    map->getValue(registrationExpireKey, &_registrationExpire);
+    map->getValue(portNumKey, &_portNum);
+    map->getValue(searchBarDisplayKey, &_searchBarDisplay);
+    map->getValue(zeroConfenableKey, &_zeroConfenable);
+    map->getValue(md5HashKey, &_md5Hash);
 }
 
 
-VoipPreference::VoipPreference() : _playDtmf (true)
-    , _playTones (true)
-    , _pulseLength (atoi (DFT_PULSE_LENGTH_STR)) // DFT_PULSE_LENGTH_STR
-    , _symmetricRtp (true)
-    , _zidFile (ZRTP_ZIDFILE) // ZRTP_ZID_FILENAME
+VoipPreference::VoipPreference() : _playDtmf(true)
+    , _playTones(true)
+    , _pulseLength(atoi(DFT_PULSE_LENGTH_STR)) // DFT_PULSE_LENGTH_STR
+    , _symmetricRtp(true)
+    , _zidFile(ZRTP_ZIDFILE) // ZRTP_ZID_FILENAME
 {}
 
-void VoipPreference::serialize (Conf::YamlEmitter *emitter)
+void VoipPreference::serialize(Conf::YamlEmitter *emitter)
 {
-    Conf::MappingNode preferencemap (NULL);
+    Conf::MappingNode preferencemap(NULL);
 
-    Conf::ScalarNode playDtmf (_playDtmf);
-    Conf::ScalarNode playTones (_playTones);
+    Conf::ScalarNode playDtmf(_playDtmf);
+    Conf::ScalarNode playTones(_playTones);
     std::stringstream pulselengthstr;
     pulselengthstr << _pulseLength;
-    Conf::ScalarNode pulseLength (pulselengthstr.str());
-    Conf::ScalarNode symmetricRtp (_symmetricRtp);
-    Conf::ScalarNode zidFile (_zidFile.c_str());
+    Conf::ScalarNode pulseLength(pulselengthstr.str());
+    Conf::ScalarNode symmetricRtp(_symmetricRtp);
+    Conf::ScalarNode zidFile(_zidFile.c_str());
 
-    preferencemap.setKeyValue (playDtmfKey, &playDtmf);
-    preferencemap.setKeyValue (playTonesKey, &playTones);
-    preferencemap.setKeyValue (pulseLengthKey, &pulseLength);
-    preferencemap.setKeyValue (symmetricRtpKey, &symmetricRtp);
-    preferencemap.setKeyValue (zidFileKey, &zidFile);
+    preferencemap.setKeyValue(playDtmfKey, &playDtmf);
+    preferencemap.setKeyValue(playTonesKey, &playTones);
+    preferencemap.setKeyValue(pulseLengthKey, &pulseLength);
+    preferencemap.setKeyValue(symmetricRtpKey, &symmetricRtp);
+    preferencemap.setKeyValue(zidFileKey, &zidFile);
 
-    emitter->serializeVoipPreference (&preferencemap);
+    emitter->serializeVoipPreference(&preferencemap);
 }
 
-void VoipPreference::unserialize (Conf::MappingNode *map)
+void VoipPreference::unserialize(Conf::MappingNode *map)
 {
     if (!map) {
-        _error ("VoipPreference: Error: Preference map is NULL");
+        _error("VoipPreference: Error: Preference map is NULL");
         return;
     }
 
-    map->getValue (playDtmfKey, &_playDtmf);
-    map->getValue (playTonesKey, &_playTones);
-    map->getValue (pulseLengthKey, &_pulseLength);
-    map->getValue (symmetricRtpKey, &_symmetricRtp);
-    map->getValue (zidFileKey, &_zidFile);
+    map->getValue(playDtmfKey, &_playDtmf);
+    map->getValue(playTonesKey, &_playTones);
+    map->getValue(pulseLengthKey, &_pulseLength);
+    map->getValue(symmetricRtpKey, &_symmetricRtp);
+    map->getValue(zidFileKey, &_zidFile);
 }
 
 
 
-AddressbookPreference::AddressbookPreference() : _photo (true)
-    , _enabled (true)
-    , _list ("")
-    , _maxResults (25)
-    , _business (true)
-    , _home (true)
-    , _mobile (true)
+AddressbookPreference::AddressbookPreference() : _photo(true)
+    , _enabled(true)
+    , _list("")
+    , _maxResults(25)
+    , _business(true)
+    , _home(true)
+    , _mobile(true)
 {}
 
-void AddressbookPreference::serialize (Conf::YamlEmitter *emitter)
+void AddressbookPreference::serialize(Conf::YamlEmitter *emitter)
 {
-    Conf::MappingNode preferencemap (NULL);
+    Conf::MappingNode preferencemap(NULL);
 
-    Conf::ScalarNode photo (_photo);
-    Conf::ScalarNode enabled (_enabled);
-    Conf::ScalarNode list (_list);
+    Conf::ScalarNode photo(_photo);
+    Conf::ScalarNode enabled(_enabled);
+    Conf::ScalarNode list(_list);
     std::stringstream maxresultstr;
     maxresultstr << _maxResults;
-    Conf::ScalarNode maxResults (maxresultstr.str());
-    Conf::ScalarNode business (_business);
-    Conf::ScalarNode home (_home);
-    Conf::ScalarNode mobile (_mobile);
+    Conf::ScalarNode maxResults(maxresultstr.str());
+    Conf::ScalarNode business(_business);
+    Conf::ScalarNode home(_home);
+    Conf::ScalarNode mobile(_mobile);
 
-    preferencemap.setKeyValue (photoKey, &photo);
-    preferencemap.setKeyValue (enabledKey, &enabled);
-    preferencemap.setKeyValue (listKey, &list);
-    preferencemap.setKeyValue (maxResultsKey, &maxResults);
-    preferencemap.setKeyValue (businessKey, &business);
-    preferencemap.setKeyValue (homeKey, &home);
-    preferencemap.setKeyValue (mobileKey, &mobile);
+    preferencemap.setKeyValue(photoKey, &photo);
+    preferencemap.setKeyValue(enabledKey, &enabled);
+    preferencemap.setKeyValue(listKey, &list);
+    preferencemap.setKeyValue(maxResultsKey, &maxResults);
+    preferencemap.setKeyValue(businessKey, &business);
+    preferencemap.setKeyValue(homeKey, &home);
+    preferencemap.setKeyValue(mobileKey, &mobile);
 
-    emitter->serializeAddressbookPreference (&preferencemap);
+    emitter->serializeAddressbookPreference(&preferencemap);
 
 }
 
-void AddressbookPreference::unserialize (Conf::MappingNode *map)
+void AddressbookPreference::unserialize(Conf::MappingNode *map)
 {
     if (!map) {
-        _error ("Addressbook: Error: Preference map is NULL");
+        _error("Addressbook: Error: Preference map is NULL");
         return;
     }
 
-    map->getValue (photoKey, &_photo);
-    map->getValue (enabledKey, &_enabled);
-    map->getValue (listKey, &_list);
-    map->getValue (maxResultsKey, &_maxResults);
-    map->getValue (businessKey, &_business);
-    map->getValue (homeKey, &_home);
-    map->getValue (mobileKey, &_mobile);
+    map->getValue(photoKey, &_photo);
+    map->getValue(enabledKey, &_enabled);
+    map->getValue(listKey, &_list);
+    map->getValue(maxResultsKey, &_maxResults);
+    map->getValue(businessKey, &_business);
+    map->getValue(homeKey, &_home);
+    map->getValue(mobileKey, &_mobile);
 }
 
 
-HookPreference::HookPreference() : _iax2Enabled (false)
-    , _numberAddPrefix ("")
-    , _numberEnabled (false)
-    , _sipEnabled (false)
-    , _urlCommand ("x-www-browser")
-    , _urlSipField ("X-sflphone-url")
+HookPreference::HookPreference() : _iax2Enabled(false)
+    , _numberAddPrefix("")
+    , _numberEnabled(false)
+    , _sipEnabled(false)
+    , _urlCommand("x-www-browser")
+    , _urlSipField("X-sflphone-url")
 {
 
 }
 
-void HookPreference::serialize (Conf::YamlEmitter *emitter)
+void HookPreference::serialize(Conf::YamlEmitter *emitter)
 {
-    Conf::MappingNode preferencemap (NULL);
-
-    Conf::ScalarNode iax2Enabled (_iax2Enabled);
-    Conf::ScalarNode numberAddPrefix (_numberAddPrefix);
-    Conf::ScalarNode numberEnabled (_numberEnabled);
-    Conf::ScalarNode sipEnabled (_sipEnabled);
-    Conf::ScalarNode urlCommand (_urlCommand);
-    Conf::ScalarNode urlSipField (_urlSipField);
-
-    preferencemap.setKeyValue (iax2EnabledKey, &iax2Enabled);
-    preferencemap.setKeyValue (numberAddPrefixKey, &numberAddPrefix);
-    preferencemap.setKeyValue (numberEnabledKey, &numberEnabled);
-    preferencemap.setKeyValue (sipEnabledKey, &sipEnabled);
-    preferencemap.setKeyValue (urlCommandKey, &urlCommand);
-    preferencemap.setKeyValue (urlSipFieldKey, &urlSipField);
-
-    emitter->serializeHooksPreference (&preferencemap);
+    Conf::MappingNode preferencemap(NULL);
+
+    Conf::ScalarNode iax2Enabled(_iax2Enabled);
+    Conf::ScalarNode numberAddPrefix(_numberAddPrefix);
+    Conf::ScalarNode numberEnabled(_numberEnabled);
+    Conf::ScalarNode sipEnabled(_sipEnabled);
+    Conf::ScalarNode urlCommand(_urlCommand);
+    Conf::ScalarNode urlSipField(_urlSipField);
+
+    preferencemap.setKeyValue(iax2EnabledKey, &iax2Enabled);
+    preferencemap.setKeyValue(numberAddPrefixKey, &numberAddPrefix);
+    preferencemap.setKeyValue(numberEnabledKey, &numberEnabled);
+    preferencemap.setKeyValue(sipEnabledKey, &sipEnabled);
+    preferencemap.setKeyValue(urlCommandKey, &urlCommand);
+    preferencemap.setKeyValue(urlSipFieldKey, &urlSipField);
+
+    emitter->serializeHooksPreference(&preferencemap);
 }
 
-void HookPreference::unserialize (Conf::MappingNode *map)
+void HookPreference::unserialize(Conf::MappingNode *map)
 {
     if (!map) {
-        _error ("Hook: Error: Preference map is NULL");
+        _error("Hook: Error: Preference map is NULL");
         return;
     }
 
-    map->getValue (iax2EnabledKey, &_iax2Enabled);
-    map->getValue (numberAddPrefixKey, &_numberAddPrefix);
-    map->getValue (numberEnabledKey, &_numberEnabled);
-    map->getValue (sipEnabledKey, &_sipEnabled);
-    map->getValue (urlCommandKey, &_urlCommand);
-    map->getValue (urlSipFieldKey, &_urlSipField);
+    map->getValue(iax2EnabledKey, &_iax2Enabled);
+    map->getValue(numberAddPrefixKey, &_numberAddPrefix);
+    map->getValue(numberEnabledKey, &_numberEnabled);
+    map->getValue(sipEnabledKey, &_sipEnabled);
+    map->getValue(urlCommandKey, &_urlCommand);
+    map->getValue(urlSipFieldKey, &_urlSipField);
 }
 
 
 
-AudioPreference::AudioPreference() : _cardin (atoi (ALSA_DFT_CARD)) // ALSA_DFT_CARD
-    , _cardout (atoi (ALSA_DFT_CARD)) // ALSA_DFT_CARD
-    , _cardring (atoi (ALSA_DFT_CARD)) // ALSA_DFT_CARD
-    , _plugin ("default") // PCM_DEFAULT
-    , _smplrate (44100) // DFT_SAMPLE_RATE
-    , _devicePlayback ("")
-    , _deviceRecord ("")
-    , _deviceRingtone ("")
-    , _recordpath ("") // DFT_RECORD_PATH
+AudioPreference::AudioPreference() :
+      _audioApi(PULSEAUDIO_API_STR)
+    , _cardin(atoi(ALSA_DFT_CARD)) // ALSA_DFT_CARD
+    , _cardout(atoi(ALSA_DFT_CARD)) // ALSA_DFT_CARD
+    , _cardring(atoi(ALSA_DFT_CARD)) // ALSA_DFT_CARD
+    , _plugin("default") // PCM_DEFAULT
+    , _smplrate(44100) // DFT_SAMPLE_RATE
+    , _devicePlayback("")
+    , _deviceRecord("")
+    , _deviceRingtone("")
+    , _recordpath("") // DFT_RECORD_PATH
     , _alwaysRecording(false)
-    , _volumemic (atoi (DFT_VOL_SPKR_STR)) // DFT_VOL_SPKR_STR
-    , _volumespkr (atoi (DFT_VOL_MICRO_STR)) // DFT_VOL_MICRO_STR
-    , _noisereduce (true)
+    , _volumemic(atoi(DFT_VOL_SPKR_STR)) // DFT_VOL_SPKR_STR
+    , _volumespkr(atoi(DFT_VOL_MICRO_STR)) // DFT_VOL_MICRO_STR
+    , _noisereduce(true)
     , _echocancel(false)
     , _echoCancelTailLength(100)
     , _echoCancelDelay(0)
 {}
 
-void AudioPreference::serialize (Conf::YamlEmitter *emitter)
+namespace {
+    void checkSoundCard(int &card, int stream)
+    {
+        if (not AlsaLayer::soundCardIndexExists(card, stream)) {
+            _warn(" Card with index %d doesn't exist or is unusable.", card);
+            card = ALSA_DFT_CARD_ID;
+        }
+    }
+}
+
+AudioLayer* AudioPreference::createAudioLayer()
 {
-    Conf::MappingNode preferencemap (NULL);
-    Conf::MappingNode alsapreferencemap (NULL);
-    Conf::MappingNode pulsepreferencemap (NULL);
+    if (_audioApi == PULSEAUDIO_API_STR and system("ps -C pulseaudio") == 0)
+        return new PulseLayer;
+    else {
+        _audioApi = ALSA_API_STR;
+        checkSoundCard(_cardin, SFL_PCM_CAPTURE);
+        checkSoundCard(_cardout, SFL_PCM_PLAYBACK);
+        checkSoundCard(_cardring, SFL_PCM_RINGTONE);
+        return new AlsaLayer;
+    }
+}
+
+AudioLayer* AudioPreference::switchAndCreateAudioLayer()
+{
+    if (_audioApi == PULSEAUDIO_API_STR)
+        _audioApi = ALSA_API_STR;
+    else
+        _audioApi = PULSEAUDIO_API_STR;
+    return createAudioLayer();
+}
+
+void AudioPreference::serialize(Conf::YamlEmitter *emitter)
+{
+    Conf::MappingNode preferencemap(NULL);
+    Conf::MappingNode alsapreferencemap(NULL);
+    Conf::MappingNode pulsepreferencemap(NULL);
 
     // alsa preference
     std::stringstream instr;
     instr << _cardin;
-    Conf::ScalarNode cardin (instr.str()); // 0
+    Conf::ScalarNode cardin(instr.str()); // 0
     std::stringstream outstr;
     outstr << _cardout;
-    Conf::ScalarNode cardout (outstr.str()); // 0
+    Conf::ScalarNode cardout(outstr.str()); // 0
     std::stringstream ringstr;
     ringstr << _cardring;
-    Conf::ScalarNode cardring (ringstr.str());// 0
-    Conf::ScalarNode plugin (_plugin); // default
+    Conf::ScalarNode cardring(ringstr.str());// 0
+    Conf::ScalarNode plugin(_plugin); // default
 
     std::stringstream ratestr;
     ratestr << _smplrate;
-    Conf::ScalarNode smplrate (ratestr.str());// 44100
+    Conf::ScalarNode smplrate(ratestr.str());// 44100
 
     //pulseaudio preference
-    Conf::ScalarNode devicePlayback (_devicePlayback);//:
-    Conf::ScalarNode deviceRecord (_deviceRecord); //:
-    Conf::ScalarNode deviceRingtone (_deviceRingtone); //:
+    Conf::ScalarNode devicePlayback(_devicePlayback);//:
+    Conf::ScalarNode deviceRecord(_deviceRecord); //:
+    Conf::ScalarNode deviceRingtone(_deviceRingtone); //:
 
     // general preference
-    Conf::ScalarNode recordpath (_recordpath); //: /home/msavard/Bureau
+    Conf::ScalarNode audioapi(_audioApi);
+    Conf::ScalarNode recordpath(_recordpath); //: /home/msavard/Bureau
     Conf::ScalarNode alwaysRecording(_alwaysRecording);
     std::stringstream micstr;
     micstr << _volumemic;
-    Conf::ScalarNode volumemic (micstr.str()); //:  100
+    Conf::ScalarNode volumemic(micstr.str()); //:  100
     std::stringstream spkrstr;
     spkrstr << _volumespkr;
-    Conf::ScalarNode volumespkr (spkrstr.str()); //: 100
-    Conf::ScalarNode noise (_noisereduce);
+    Conf::ScalarNode volumespkr(spkrstr.str()); //: 100
+    Conf::ScalarNode noise(_noisereduce);
     Conf::ScalarNode echo(_echocancel);
     std::stringstream tailstr;
     _debug("************************************************** serialize echotail %d", _echoCancelTailLength);
@@ -349,57 +359,58 @@ void AudioPreference::serialize (Conf::YamlEmitter *emitter)
     delaystr << _echoCancelDelay;
     Conf::ScalarNode echodelay(delaystr.str());
 
-    preferencemap.setKeyValue (recordpathKey, &recordpath);
-    preferencemap.setKeyValue (alwaysRecordingKey, &alwaysRecording);
-    preferencemap.setKeyValue (volumemicKey, &volumemic);
-    preferencemap.setKeyValue (volumespkrKey, &volumespkr);
-
-    preferencemap.setKeyValue (alsamapKey, &alsapreferencemap);
-    alsapreferencemap.setKeyValue (cardinKey, &cardin);
-    alsapreferencemap.setKeyValue (cardoutKey, &cardout);
-    alsapreferencemap.setKeyValue (cardringKey, &cardring);
-    alsapreferencemap.setKeyValue (pluginKey, &plugin);
-    alsapreferencemap.setKeyValue (smplrateKey, &smplrate);
-
-    preferencemap.setKeyValue (pulsemapKey, &pulsepreferencemap);
-    pulsepreferencemap.setKeyValue (devicePlaybackKey, &devicePlayback);
-    pulsepreferencemap.setKeyValue (deviceRecordKey, &deviceRecord);
-    pulsepreferencemap.setKeyValue (deviceRingtoneKey, &deviceRingtone);
-
-    preferencemap.setKeyValue (noiseReduceKey, &noise);
+    preferencemap.setKeyValue(audioApiKey, &audioapi);
+    preferencemap.setKeyValue(recordpathKey, &recordpath);
+    preferencemap.setKeyValue(alwaysRecordingKey, &alwaysRecording);
+    preferencemap.setKeyValue(volumemicKey, &volumemic);
+    preferencemap.setKeyValue(volumespkrKey, &volumespkr);
+
+    preferencemap.setKeyValue(alsamapKey, &alsapreferencemap);
+    alsapreferencemap.setKeyValue(cardinKey, &cardin);
+    alsapreferencemap.setKeyValue(cardoutKey, &cardout);
+    alsapreferencemap.setKeyValue(cardringKey, &cardring);
+    alsapreferencemap.setKeyValue(pluginKey, &plugin);
+    alsapreferencemap.setKeyValue(smplrateKey, &smplrate);
+
+    preferencemap.setKeyValue(pulsemapKey, &pulsepreferencemap);
+    pulsepreferencemap.setKeyValue(devicePlaybackKey, &devicePlayback);
+    pulsepreferencemap.setKeyValue(deviceRecordKey, &deviceRecord);
+    pulsepreferencemap.setKeyValue(deviceRingtoneKey, &deviceRingtone);
+
+    preferencemap.setKeyValue(noiseReduceKey, &noise);
     preferencemap.setKeyValue(echoCancelKey, &echo);
     preferencemap.setKeyValue(echoTailKey, &echotail);
     preferencemap.setKeyValue(echoDelayKey, &echodelay);
 
-    emitter->serializeAudioPreference (&preferencemap);
-
+    emitter->serializeAudioPreference(&preferencemap);
 }
 
-void AudioPreference::unserialize (Conf::MappingNode *map)
+void AudioPreference::unserialize(Conf::MappingNode *map)
 {
 	assert(map);
 
-    map->getValue (recordpathKey, &_recordpath);
-    map->getValue (alwaysRecordingKey, &_alwaysRecording);
-    map->getValue (volumemicKey, &_volumemic);
-    map->getValue (volumespkrKey, &_volumespkr);
-    map->getValue (noiseReduceKey, &_noisereduce);
+    map->getValue(audioApiKey, &_audioApi);
+    map->getValue(recordpathKey, &_recordpath);
+    map->getValue(alwaysRecordingKey, &_alwaysRecording);
+    map->getValue(volumemicKey, &_volumemic);
+    map->getValue(volumespkrKey, &_volumespkr);
+    map->getValue(noiseReduceKey, &_noisereduce);
     map->getValue(echoCancelKey, &_echocancel);
 
-    Conf::MappingNode *alsamap = (Conf::MappingNode *) (map->getValue ("alsa"));
+    Conf::MappingNode *alsamap =(Conf::MappingNode *)(map->getValue("alsa"));
     if (alsamap) {
-    	alsamap->getValue (cardinKey, &_cardin);
-		alsamap->getValue (cardoutKey, &_cardout);
-		alsamap->getValue (cardringKey, &_cardring);
-		alsamap->getValue (smplrateKey, &_smplrate);
-		alsamap->getValue (pluginKey, &_plugin);
+        alsamap->getValue(cardinKey, &_cardin);
+		alsamap->getValue(cardoutKey, &_cardout);
+		alsamap->getValue(cardringKey, &_cardring);
+		alsamap->getValue(smplrateKey, &_smplrate);
+		alsamap->getValue(pluginKey, &_plugin);
     }
 
-    Conf::MappingNode *pulsemap = (Conf::MappingNode *) (map->getValue ("pulse"));
+    Conf::MappingNode *pulsemap =(Conf::MappingNode *)(map->getValue("pulse"));
     if (pulsemap) {
-    	pulsemap->getValue (devicePlaybackKey, &_devicePlayback);
-    	pulsemap->getValue (deviceRecordKey, &_deviceRecord);
-    	pulsemap->getValue (deviceRingtoneKey, &_deviceRingtone);
+        pulsemap->getValue(devicePlaybackKey, &_devicePlayback);
+        pulsemap->getValue(deviceRecordKey, &_deviceRecord);
+        pulsemap->getValue(deviceRingtoneKey, &_deviceRingtone);
     }
 }
 
@@ -417,7 +428,7 @@ std::map<std::string, std::string> ShortcutPreferences::getShortcuts() const
 }
 
 
-void ShortcutPreferences::setShortcuts (std::map<std::string, std::string> map)
+void ShortcutPreferences::setShortcuts(std::map<std::string, std::string> map)
 {
     _hangup = map[hangupShortKey];
     _pickup = map[pickupShortKey];
@@ -427,34 +438,34 @@ void ShortcutPreferences::setShortcuts (std::map<std::string, std::string> map)
 }
 
 
-void ShortcutPreferences::serialize (Conf::YamlEmitter *emitter)
+void ShortcutPreferences::serialize(Conf::YamlEmitter *emitter)
 {
-    Conf::MappingNode preferencemap (NULL);
+    Conf::MappingNode preferencemap(NULL);
 
-    Conf::ScalarNode hangup (_hangup);
-    Conf::ScalarNode pickup (_pickup);
-    Conf::ScalarNode popup (_popup);
-    Conf::ScalarNode toggleHold (_toggleHold);
-    Conf::ScalarNode togglePickupHangup (_togglePickupHangup);
+    Conf::ScalarNode hangup(_hangup);
+    Conf::ScalarNode pickup(_pickup);
+    Conf::ScalarNode popup(_popup);
+    Conf::ScalarNode toggleHold(_toggleHold);
+    Conf::ScalarNode togglePickupHangup(_togglePickupHangup);
 
-    preferencemap.setKeyValue (hangupShortKey, &hangup);
-    preferencemap.setKeyValue (pickupShortKey, &pickup);
-    preferencemap.setKeyValue (popupShortKey, &popup);
-    preferencemap.setKeyValue (toggleHoldShortKey, &toggleHold);
-    preferencemap.setKeyValue (togglePickupHangupShortKey, &togglePickupHangup);
+    preferencemap.setKeyValue(hangupShortKey, &hangup);
+    preferencemap.setKeyValue(pickupShortKey, &pickup);
+    preferencemap.setKeyValue(popupShortKey, &popup);
+    preferencemap.setKeyValue(toggleHoldShortKey, &toggleHold);
+    preferencemap.setKeyValue(togglePickupHangupShortKey, &togglePickupHangup);
 
-    emitter->serializeShortcutPreference (&preferencemap);
+    emitter->serializeShortcutPreference(&preferencemap);
 }
 
-void ShortcutPreferences::unserialize (Conf::MappingNode *map)
+void ShortcutPreferences::unserialize(Conf::MappingNode *map)
 {
     if (map == NULL) {
-        _error ("ShortcutPreference: Error: Preference map is NULL");
+        _error("ShortcutPreference: Error: Preference map is NULL");
         return;
     }
-    map->getValue (hangupShortKey, &_hangup);
-    map->getValue (pickupShortKey, &_pickup);
-    map->getValue (popupShortKey, &_popup);
-    map->getValue (toggleHoldShortKey, &_toggleHold);
-    map->getValue (togglePickupHangupShortKey, &_togglePickupHangup);
+    map->getValue(hangupShortKey, &_hangup);
+    map->getValue(pickupShortKey, &_pickup);
+    map->getValue(popupShortKey, &_popup);
+    map->getValue(toggleHoldShortKey, &_toggleHold);
+    map->getValue(togglePickupHangupShortKey, &_togglePickupHangup);
 }
diff --git a/daemon/src/preferences.h b/daemon/src/preferences.h
index a974d6391a0923a89781d241404cea6cba3fe4e6..0c8c3e6b7aafbfa0863dac82e504729c1896d920 100644
--- a/daemon/src/preferences.h
+++ b/daemon/src/preferences.h
@@ -108,9 +108,6 @@ class Preferences : public Serializable
 
         Preferences();
 
-        AudioLayer *createAudioLayer();
-        AudioLayer *switchAndCreateAudioLayer();
-
         virtual void serialize (Conf::YamlEmitter *emitter);
 
         virtual void unserialize (Conf::MappingNode *map);
@@ -123,13 +120,6 @@ class Preferences : public Serializable
             _accountOrder = ord;
         }
 
-        std::string getAudioApi (void) const {
-            return _audioApi;
-        }
-        void setAudioApi (const std::string &api) {
-            _audioApi = api;
-        }
-
         int getHistoryLimit (void) const {
             return _historyLimit;
         }
@@ -198,7 +188,6 @@ class Preferences : public Serializable
         // account order
         std::string _accountOrder;
 
-        std::string _audioApi;
         int _historyLimit;
         int _historyMaxCalls;
         bool _notifyMails;
@@ -402,6 +391,16 @@ class AudioPreference : public Serializable
 {
     public:
         AudioPreference();
+        AudioLayer *createAudioLayer();
+        AudioLayer *switchAndCreateAudioLayer();
+
+        std::string getAudioApi (void) const {
+            return _audioApi;
+        }
+
+        void setAudioApi (const std::string &api) {
+            _audioApi = api;
+        }
         virtual void serialize (Conf::YamlEmitter *emitter);
 
         virtual void unserialize (Conf::MappingNode *map);
@@ -530,6 +529,7 @@ class AudioPreference : public Serializable
         }
 
     private:
+        std::string _audioApi;
 
         // alsa preference
         int _cardin; // 0
diff --git a/daemon/test/configurationtest.cpp b/daemon/test/configurationtest.cpp
index 8edd0f826f90362062684acfc286f9d63097959c..aad1fdfc0ba414111de3e638d729bc0d8280c4a5 100644
--- a/daemon/test/configurationtest.cpp
+++ b/daemon/test/configurationtest.cpp
@@ -81,9 +81,9 @@ void ConfigurationTest::testInitAudioDriver()
         CPPUNIT_FAIL ("Error while loading audio layer");
 
     // Check if it has been created with the right type
-    if (Manager::instance().preferences.getAudioApi() == "alsa")
+    if (Manager::instance().audioPreference.getAudioApi() == "alsa")
         CPPUNIT_ASSERT (!dynamic_cast<PulseLayer*>(Manager::instance().getAudioDriver()));
-    else if (Manager::instance().preferences.getAudioApi() == "pulseaudio")
+    else if (Manager::instance().audioPreference.getAudioApi() == "pulseaudio")
         CPPUNIT_ASSERT (!dynamic_cast<AlsaLayer*>(Manager::instance().getAudioDriver()));
     else
         CPPUNIT_FAIL ("Wrong audio layer type");