diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
index fa079fd9f595b4d302523de1ee74aa74c7a16f02..740a7957262686a04546da372b44f88310eaf9ed 100644
--- a/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
+++ b/sflphone-common/src/audio/pulseaudio/pulselayer.cpp
@@ -41,6 +41,15 @@ static void capture_callback (pa_stream* s, size_t bytes, void* userdata)
     
 }
 
+static void ringtone_callback (pa_stream* s, size_t bytes, void* userdata)
+{
+
+    assert(s && bytes);
+    assert(bytes > 0);
+    static_cast<PulseLayer*> (userdata)->processRingtoneData();
+
+}
+
 /*
 static void stream_suspended_callback (pa_stream *s UNUSED, void *userdata UNUSED)
 {
@@ -278,7 +287,7 @@ bool PulseLayer::createStreams (pa_context* c)
     // pa_stream_set_suspended_callback(record->pulseStream(), stream_suspended_callback, this);
     // pa_stream_set_moved_callback(record->pulseStream(), stream_moved_callback, this);
     delete recordParam;
-
+    
     PulseLayerType * ringtoneParam = new PulseLayerType();
     ringtoneParam->context = c;
     ringtoneParam->type = RINGTONE_STREAM;
@@ -288,7 +297,7 @@ bool PulseLayer::createStreams (pa_context* c)
 
     ringtone = new AudioStream (ringtoneParam, _audioSampleRate);
     ringtone->connectStream();
-    pa_stream_set_write_callback(ringtone->pulseStream(), playback_callback, this);
+    pa_stream_set_write_callback(ringtone->pulseStream(), ringtone_callback, this);
     delete ringtoneParam;
 
     pa_threaded_mainloop_signal (m , 0);
@@ -329,6 +338,13 @@ void PulseLayer::closePlaybackStream (void)
         delete playback;
         playback=NULL;
     }
+
+    if(ringtone) {
+        delete ringtone;
+	ringtone  = NULL;
+    }
+
+    _debug("ringtone is dead");
 }
 
 
@@ -353,8 +369,8 @@ int PulseLayer::getMic (void *buffer, int toCopy)
 void PulseLayer::startStream (void)
 {
     // Create Streams
-	if(!playback || !record)
-		createStreams(context);
+    if(!playback || !record)
+        createStreams(context);
 
     // Flush outside the if statement: every time start stream is
     // called is to notify a new event
@@ -411,6 +427,19 @@ void PulseLayer::processCaptureData (void)
 
 }
 
+void PulseLayer::processRingtoneData (void)
+{
+    // handle ringtone playback
+  if(ringtone && (ringtone)->pulseStream() && (pa_stream_get_state(ringtone->pulseStream()) == PA_STREAM_READY)) {
+    
+    // If the playback buffer is full, we don't overflow it; wait for it to have free space
+    if(pa_stream_writable_size(ringtone->pulseStream()) == 0)
+      return;
+
+    ringtoneToSpeaker();
+  }
+}
+
 
 void PulseLayer::processData (void)
 {
@@ -487,10 +516,11 @@ void PulseLayer::writeToSpeaker (void)
                 pa_xfree (out);
 
             }
-        }
+	    //}
 
-        else if (file_tone != 0) {
+        // else if (file_tone != 0) {
 
+	  /*
             if (playback->getStreamState() == PA_STREAM_READY) {
 
                 out = (SFLDataFormat*) pa_xmalloc (writeableSize);
@@ -501,6 +531,7 @@ void PulseLayer::writeToSpeaker (void)
                 pa_xfree (out);
 
             }
+	  */
 
         } else {
 
@@ -641,6 +672,43 @@ void PulseLayer::readFromMic (void)
 
 }
 
+
+void PulseLayer::ringtoneToSpeaker(void)
+{
+  int availBytes;
+
+  AudioLoop* file_tone = _manager->getTelephoneFile();
+
+  SFLDataFormat* out;
+
+  int writableSize = pa_stream_writable_size(ringtone->pulseStream());
+
+  _debug("writable size: %d", writableSize);
+
+  if (file_tone) {
+
+    if(ringtone->getStreamState() == PA_STREAM_READY) {
+      
+      out = (SFLDataFormat*)pa_xmalloc(writableSize);
+      int copied = file_tone->getNext(out, writableSize/sizeof(SFLDataFormat), 100);
+      pa_stream_write(ringtone->pulseStream(), out, copied*sizeof(SFLDataFormat), NULL, 0, PA_SEEK_RELATIVE);
+
+      pa_xfree(out);
+
+    }
+  }
+  else {
+
+    out = (SFLDataFormat*)pa_xmalloc(writableSize);
+    memset(out, 0, writableSize);
+    pa_stream_write(ringtone->pulseStream(), out, writableSize, NULL, 0, PA_SEEK_RELATIVE);
+    
+    pa_xfree(out);
+  }
+    
+
+}
+
 static void retrieve_server_info (pa_context *c UNUSED, const pa_server_info *i, void *userdata UNUSED)
 {
     _debug ("Server Info: Process owner : %s" , i->user_name);
diff --git a/sflphone-common/src/audio/pulseaudio/pulselayer.h b/sflphone-common/src/audio/pulseaudio/pulselayer.h
index 817a75288b2a77344ab8568e269d734783084b88..59be37092f966cf3fcb7fe147ec7d9fb844e9fc6 100644
--- a/sflphone-common/src/audio/pulseaudio/pulselayer.h
+++ b/sflphone-common/src/audio/pulseaudio/pulselayer.h
@@ -140,6 +140,8 @@ class PulseLayer : public AudioLayer {
 
     void processCaptureData( void );
 
+    void processRingtoneData( void );
+
     void processData(void);
     
   private:
@@ -160,6 +162,7 @@ class PulseLayer : public AudioLayer {
      */
     void readFromMic( void );
     void writeToSpeaker( void );
+    void ringtoneToSpeaker( void );
     
     /**
      * Create the audio streams into the given context
diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp
index 397e11e2e9d4548834c626571c2f5d8521221b3a..920db606a43af1d36e35834756ebd4f4305f78de 100644
--- a/sflphone-common/src/managerimpl.cpp
+++ b/sflphone-common/src/managerimpl.cpp
@@ -3864,15 +3864,19 @@ void ManagerImpl::unloadAccountMap () {
 
 	while (iter != _accountMap.end()) {
 
-		_debug ("Unloading account %s\n", iter->first.c_str());
+		_debug ("Unloading account %s", iter->first.c_str());
 
 		delete iter->second;
-		iter->second = 0;
+		iter->second = NULL;
 
 		iter++;
 	}
 
+	_debug("Manager: Clear account map");
 	_accountMap.clear();
+	_debug("Manager: Unload account map");
+
+	
 }
 
 bool ManagerImpl::accountExists (const AccountID& accountID) {
diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp
index fd8639d94a7fb11b10faa6bff6e91ef620cc22c2..3a3df884beff8615dbf7dfc1f25dc24048138d23 100644
--- a/sflphone-common/src/sip/sipvoiplink.cpp
+++ b/sflphone-common/src/sip/sipvoiplink.cpp
@@ -332,6 +332,8 @@ SIPVoIPLink::terminate()
     }
 
     initDone (false);
+
+    _debug("Terminating");
 }
 
 void