diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp
index cc7e147a8b12f7549173727a6fa01d02d1f934ea..d70e1221216de4257fe15373b637d39446152286 100644
--- a/src/sipvoiplink.cpp
+++ b/src/sipvoiplink.cpp
@@ -259,49 +259,59 @@ SIPVoIPLink::onhold(const CallID& id)
   _debug("* SIP Info: Stopping AudioRTP for onhold action\n");
   _audiortp->closeRtpSession();
 
-  Manager::instance().getUserAgent()->onhold(call);
-
-  return true;
+  return Manager::instance().getUserAgent()->onhold(call);
 }
 
 bool 
 SIPVoIPLink::offhold(const CallID& id)
 {
-  SIPCall* call = getSIPCall(id);
-  if (call==0) { _debug("! SIP Error: Call doesn't exist\n"); return false; }
+    SIPCall *call;
 
-  Manager::instance().getUserAgent()->offhold(call);
+    call = getSIPCall(id);
+    if (call==0) { 
+        _debug("! SIP Error: Call doesn't exist\n"); 
+        return false; 
+    }
 
-  // Enable audio
-  _debug("* SIP Info: Starting AudioRTP when offhold\n");
-  call->setState(Call::Active);
-  // it's sure that this is the current call id...
-  if (_audiortp->createNewSession(call) < 0) {
-    _debug("! SIP Failure: Unable to start sound (%s:%d)\n", __FILE__, __LINE__);
-    return false;
-  }
-  return true;
+    if(!Manager::instance().getUserAgent()->offhold(call))
+        return false;
+
+    // Enable audio
+    _debug("* SIP Info: Starting AudioRTP when offhold\n");
+    call->setState(Call::Active);
+    // it's sure that this is the current call id...
+    if (_audiortp->createNewSession(call) < 0) {
+        _debug("! SIP Failure: Unable to start sound (%s:%d)\n", __FILE__, __LINE__);
+        return false;
+    }
+    
+    return true;
 }
 
 bool 
 SIPVoIPLink::transfer(const CallID& id, const std::string& to)
 {
-  SIPCall* call = getSIPCall(id);
-  if (call==0) { _debug("! SIP Failure: Call doesn't exist\n"); return false; }  
+    SIPCall *call;
+    std::string tmp_to;
 
-  std::string tmp_to = SIPToHeader(to);
-  if (tmp_to.find("@") == std::string::npos) {
-    tmp_to = tmp_to + "@" + getHostname();
-  }
+    call = getSIPCall(id);
+    if (call==0) { 
+        _debug("! SIP Failure: Call doesn't exist\n"); 
+        return false; 
+    }  
+
+    tmp_to = SIPToHeader(to);
+    if (tmp_to.find("@") == std::string::npos) {
+        tmp_to = tmp_to + "@" + getHostname();
+    }
 
-  _debug("In transfer, tmp_to is %s\n", tmp_to.data());
+    _debug("In transfer, tmp_to is %s\n", tmp_to.data());
 
-  Manager::instance().getUserAgent()->transfer(call, tmp_to);
+    return Manager::instance().getUserAgent()->transfer(call, tmp_to);
 
   //_audiortp->closeRtpSession();
   // shall we delete the call?
   //removeCall(id);
-  return true;
 }
 
 bool SIPVoIPLink::transferStep2()
@@ -313,34 +323,45 @@ bool SIPVoIPLink::transferStep2()
 bool
 SIPVoIPLink::refuse (const CallID& id)
 {
-  SIPCall* call = getSIPCall(id);
+    SIPCall *call;
 
-  if (call==0) { _debug("Call doesn't exist\n"); return false; }  
+    call = getSIPCall(id);
 
-  // can't refuse outgoing call or connected
-  if (!call->isIncoming() || call->getConnectionState() == Call::Connected) { 
-    _debug("It's not an incoming call, or it's already answered\n");
-    return false; 
-  }
+    if (call==0) { 
+        _debug("Call doesn't exist\n"); 
+        return false; 
+    }  
 
-  Manager::instance().getUserAgent()->refuse(call);
-  
-  return true;
+    // can't refuse outgoing call or connected
+    if (!call->isIncoming() || call->getConnectionState() == Call::Connected) { 
+        _debug("It's not an incoming call, or it's already answered\n");
+        return false; 
+    }
+
+    return Manager::instance().getUserAgent()->refuse(call);
 }
 
 bool 
-SIPVoIPLink::carryingDTMFdigits(const CallID& id, char code UNUSED)
+SIPVoIPLink::carryingDTMFdigits(const CallID& id, char code)
 {
-  SIPCall* call = getSIPCall(id);
-  if (call==0) { _debug("Call doesn't exist\n"); return false; }
 
-  int duration = Manager::instance().getConfigInt(SIGNALISATION, PULSE_LENGTH);
-  const int body_len = 1000;
-  char *dtmf_body = new char[body_len];
+    SIPCall *call;
+    int duration;
+    const int body_len = 1000;
+    char *dtmf_body;
+
+    call = getSIPCall(id);
+    if (call==0) { 
+        _debug("Call doesn't exist\n"); 
+        return false; 
+    }
+
+    duration = Manager::instance().getConfigInt(SIGNALISATION, PULSE_LENGTH);
+    dtmf_body = new char[body_len];
  
-  snprintf(dtmf_body, body_len - 1, "Signal=%c\r\nDuration=%d\r\n", code, duration);
+    snprintf(dtmf_body, body_len - 1, "Signal=%c\r\nDuration=%d\r\n", code, duration);
  
-  return Manager::instance().getUserAgent()->carryingDTMFdigits(call, dtmf_body);
+    return Manager::instance().getUserAgent()->carryingDTMFdigits(call, dtmf_body);
 }
 
 bool
@@ -447,9 +468,9 @@ SIPVoIPLink::SIPCallServerFailure(SIPCall *call)
     //SIPCall* call = findSIPCallWithCid(event->cid);
     if (call != 0) {
         _debug("Server error!\n");
-      CallID id = call->getCallId();
-      Manager::instance().callFailure(id);
-      removeCall(id);
+        CallID id = call->getCallId();
+        Manager::instance().callFailure(id);
+        removeCall(id);
     }
   //break;
   //}
@@ -522,45 +543,6 @@ SIPVoIPLink::SIPCallAnswered(SIPCall *call, pjsip_rx_data *rdata)
   }
 }
 
-SIPCall* 
-SIPVoIPLink::findSIPCallWithCid(int cid) 
-{
-  if (cid < 1) {
-    _debug("! SIP Error: Not enough information for this event\n");
-    return NULL;
-  }
-  ost::MutexLock m(_callMapMutex);
-  SIPCall* call = 0;
-  CallMap::iterator iter = _callMap.begin();
-  while(iter != _callMap.end()) {
-    call = dynamic_cast<SIPCall*>(iter->second);
-    if (call && call->getCid() == cid) {
-      return call;
-    }
-    iter++;
-  }
-  return NULL;
-}
-
-SIPCall* 
-SIPVoIPLink::findSIPCallWithCidDid(int cid, int did) 
-{
-  if (cid < 1 && did < -1) {
-    _debug("! SIP Error: Not enough information for this event\n");
-    return NULL;
-  }
-  ost::MutexLock m(_callMapMutex);
-  SIPCall* call = 0;
-  CallMap::iterator iter = _callMap.begin();
-  while(iter != _callMap.end()) {
-    call = dynamic_cast<SIPCall*>(iter->second);
-    if (call && call->getCid() == cid && call->getDid() == did) {
-      return call;
-    }
-    iter++;
-  }
-  return NULL;
-}
 
 SIPCall*
 SIPVoIPLink::getSIPCall(const CallID& id) 
@@ -571,61 +553,7 @@ SIPVoIPLink::getSIPCall(const CallID& id)
   }
   return NULL;
 }
-/*
-bool
-SIPVoIPLink::handleDtmfRelay(eXosip_event_t* event) {
-
-  SIPCall* call = findSIPCallWithCidDid(event->cid, event->did);
-  if (call==0) { return false; }
-
-
-  bool returnValue = false;
-  osip_body_t *body = NULL;
-  // Get the message body
-  if (0 == osip_message_get_body(event->request, 0, &body) && body->body != 0 )   {
-    _debug("* SIP Info: Text body: %s\n", body->body);
-    std::string dtmfBody(body->body);
-    std::string::size_type posStart = 0;
-    std::string::size_type posEnd = 0;
-    std::string signal;
-    std::string duration;
-    // search for signal=and duration=
-    posStart = dtmfBody.find("Signal=");
-    if (posStart != std::string::npos) {
-      posStart += strlen("Signal=");
-      posEnd = dtmfBody.find("\n", posStart);
-      if (posEnd == std::string::npos) {
-        posEnd = dtmfBody.length();
-      }
-      signal = dtmfBody.substr(posStart, posEnd-posStart+1);
-      _debug("* SIP Info: Signal value: %s\n", signal.c_str());
-      
-      if (!signal.empty()) {
-        if (Manager::instance().isCurrentCall(call->getCallId())) {
-          Manager::instance().playDtmf(signal[0], true);
-          returnValue = true;
-        }
-      }
-
- // we receive the duration, but we use our configuration...
-
-      posStart = dtmfBody.find("Duration=");
-      if (posStart != std::string::npos) {
-        posStart += strlen("Duration=");
-        posEnd = dtmfBody.find("\n", posStart);
-        if (posEnd == std::string::npos) {
-            posEnd = dtmfBody.length();
-        }
-        duration = dtmfBody.substr(posStart, posEnd-posStart+1);
-        _debug("Duration value: %s\n", duration.c_str());
-        returnValue = true;
-      }
 
-    }
-  }
-  return returnValue;
-}
-*/
 ///////////////////////////////////////////////////////////////////////////////
 // Private functions
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/src/sipvoiplink.h b/src/sipvoiplink.h
index fb863c491ab20b61e5034cff70460240a1835503..865703e2151eb4345c40e178b5fa2187aa06230a 100644
--- a/src/sipvoiplink.h
+++ b/src/sipvoiplink.h
@@ -268,22 +268,6 @@ class SIPVoIPLink : public VoIPLink
      */
     void SIPCallReleased(SIPCall *call);
 
-    /**
-     * Find a SIPCall with cid
-     * Explication there is no DID when the dialog is not establish...
-     * @param cid call ID
-     * @return SIPCall*	SIPCall pointer or 0
-     */
-    SIPCall* findSIPCallWithCid(int cid);
-
-    /**
-     * Find a SIPCall with cid and did
-     * @param cid call ID
-     * @param did domain ID
-     * @return SIPCall*	SIPCall pointer or 0
-     */
-    SIPCall* findSIPCallWithCidDid(int cid, int did);
-
     /**
      * SIPCall accessor
      * @param id  The call identifier
diff --git a/src/useragent.cpp b/src/useragent.cpp
index cb39635f05d2593c5090cd43e6c501a683aa9db1..fb527784e0a41d0754228debb329860589370d0c 100644
--- a/src/useragent.cpp
+++ b/src/useragent.cpp
@@ -1126,42 +1126,65 @@ void UserAgent::call_on_state_changed(pjsip_inv_session *inv, pjsip_event *e) {
 }
 
 bool UserAgent::onhold(SIPCall *call) {
-    _debug("UserAgent: Before onhold pjsip_inv_reinite begins!\n");
+
     pj_status_t status;
     pjsip_tx_data *tdata;
     pjmedia_sdp_attr *attr;
+    pjmedia_sdp_session* local_sdp;
 
+    local_sdp = call->getLocalSDPSession();
+    if( local_sdp == NULL ){
+        _debug("! SIP Failure: unable to find local_sdp\n");
+        return false;
+    }
 
     /* Create re-INVITE with new offer */
-    pjmedia_sdp_media_remove_all_attr(call->getLocalSDPSession()->media[0], "sendrecv");
+    // Remove all the attributes with the specified name
+    pjmedia_sdp_media_remove_all_attr(local_sdp->media[0], "sendrecv");
     attr = pjmedia_sdp_attr_create(_pool, "sendonly", NULL);
-    pjmedia_sdp_media_add_attr(call->getLocalSDPSession()->media[0], attr);
+    pjmedia_sdp_media_add_attr(local_sdp->media[0], attr);
 
-    status = pjsip_inv_reinvite( call->getInvSession(), NULL, call->getLocalSDPSession(), &tdata);
+    status = pjsip_inv_reinvite( call->getInvSession(), NULL, local_sdp, &tdata);
+    if( status != PJ_SUCCESS )
+    {
+        _debug("On hold: creation of the Re-invite request failed\n");
+        return false;
+    }
     /* Send the request */
     status = pjsip_inv_send_msg( call->getInvSession(), tdata);
  
-    _debug("UserAgent: After pjsip_inv_reinite begins!\n");
     return (status == PJ_SUCCESS);
 }
 
 bool UserAgent::offhold(SIPCall *call) {
-    _debug("UserAgent: Before offhold pjsip_inv_reinite begins!\n");
+
     pj_status_t status;
     pjsip_tx_data *tdata;
     pjmedia_sdp_attr *attr;
+    pjmedia_sdp_session* local_sdp;
 
+    local_sdp = call->getLocalSDPSession();
+    if( local_sdp == NULL ){
+        _debug("! SIP Failure: unable to find local_sdp\n");
+        return false;
+    }
 
     /* Create re-INVITE with new offer */
-    pjmedia_sdp_media_remove_all_attr(call->getLocalSDPSession()->media[0], "sendonly");
+    // Remove all the attributes with the specified name
+    pjmedia_sdp_media_remove_all_attr(local_sdp->media[0], "sendonly");
     attr = pjmedia_sdp_attr_create(_pool, "sendrecv", NULL);
-    pjmedia_sdp_media_add_attr(call->getLocalSDPSession()->media[0], attr);
+    pjmedia_sdp_media_add_attr(local_sdp->media[0], attr);
+
+    status = pjsip_inv_reinvite( call->getInvSession(), NULL, local_sdp , &tdata);
+    if( status != PJ_SUCCESS )
+    {
+        _debug("Off hold: creation of the Re-invite request failed\n");
+        return false;
+    }
 
-    status = pjsip_inv_reinvite( call->getInvSession(), NULL, call->getLocalSDPSession(), &tdata);
     /* Send the request */
     status = pjsip_inv_send_msg( call->getInvSession(), tdata);
  
-    _debug("UserAgent: After pjsip_inv_reinite begins!\n");
     return (status == PJ_SUCCESS);
 }
 
@@ -1194,10 +1217,12 @@ bool UserAgent::refuse(SIPCall* call)
     
     // User refuse current call. Notify peer
     status = pjsip_inv_end_session(call->getInvSession(), PJSIP_SC_DECLINE, NULL, &tdata); //603
-    PJ_ASSERT_RETURN(status == PJ_SUCCESS, false);
+    if(status != PJ_SUCCESS)
+        return false;
 
     status = pjsip_inv_send_msg(call->getInvSession(), tdata);
-    PJ_ASSERT_RETURN(status == PJ_SUCCESS, false);
+    if(status != PJ_SUCCESS)
+        return false;
 
     call->getInvSession()->mod_data[getInstance()->getModId()] = NULL;
     return true;
@@ -1253,9 +1278,6 @@ bool UserAgent::transfer(SIPCall *call, const std::string& to)
 {
     pjsip_evsub *sub;
     pjsip_tx_data *tdata;
-    //pjsip_dialog *dlg;
-    //pjsip_generic_string_hdr *gs_hdr;
-    //const pj_str_t str_ref_by = { (char*)"Referred-By", 11 };
     struct pjsip_evsub_user xfer_cb;
     pj_status_t status;
     pj_str_t dest;