diff --git a/daemon/commands/audio-codec-get.cc b/daemon/commands/audio-codec-get.cc
index c8bdd861d4901a7b012a50837b2d8e9c79d9da35..48bd25f05214b319d4f3d11d285499852d0e2143 100644
--- a/daemon/commands/audio-codec-get.cc
+++ b/daemon/commands/audio-codec-get.cc
@@ -34,11 +34,11 @@ AudioCodecGetCommand::AudioCodecGetCommand() :
 }
 
 void AudioCodecGetCommand::exec(Daemon *app, const char *args) {
-	int ptnum;
 	bool list = false;
 	bool found = false;
 	istringstream ist(args);
 	ostringstream ost;
+	PayloadType *pt=NULL;
 
 	if (ist.peek() == EOF) {
 		found = list = true;
@@ -50,7 +50,7 @@ void AudioCodecGetCommand::exec(Daemon *app, const char *args) {
 			app->sendResponse(Response("Incorrect mime type format.", Response::Error));
 			return;
 		}
-		ptnum = parser.payloadTypeNumber();
+		pt = parser.getPayloadType();
 	}
 
 	int index = 0;
@@ -58,7 +58,7 @@ void AudioCodecGetCommand::exec(Daemon *app, const char *args) {
 		PayloadType *payload = reinterpret_cast<PayloadType*>(node->data);
 		if (list) {
 			ost << PayloadTypeResponse(app->getCore(), payload, index).getBody() << "\n";
-		} else if (ptnum == linphone_core_get_payload_type_number(app->getCore(), payload)) {
+		} else if (pt == payload) {
 			ost << PayloadTypeResponse(app->getCore(), payload, index).getBody();
 			found = true;
 			break;
diff --git a/daemon/commands/audio-codec-move.cc b/daemon/commands/audio-codec-move.cc
index b77912f32b74d723f591d5c1562802a3e63c0498..3d65f91135ba27525cf995a8b940e44b07eb473e 100644
--- a/daemon/commands/audio-codec-move.cc
+++ b/daemon/commands/audio-codec-move.cc
@@ -49,7 +49,14 @@ void AudioCodecMoveCommand::exec(Daemon *app, const char *args) {
 		app->sendResponse(Response("Incorrect mime type format.", Response::Error));
 		return;
 	}
-	int ptnum = parser.payloadTypeNumber();
+	PayloadType *selected_payload = NULL;
+	selected_payload = parser.getPayloadType();
+	
+	if (selected_payload == NULL) {
+		app->sendResponse(Response("Audio codec not found.", Response::Error));
+		return;
+	}
+	
 	int index;
 	ist >> index;
 	if (ist.fail() || (index < 0)) {
@@ -57,19 +64,6 @@ void AudioCodecMoveCommand::exec(Daemon *app, const char *args) {
 		return;
 	}
 
-	PayloadType *selected_payload = NULL;
-	for (const MSList *node = linphone_core_get_audio_codecs(app->getCore()); node != NULL; node = ms_list_next(node)) {
-		PayloadType *payload = reinterpret_cast<PayloadType*>(node->data);
-		if (ptnum == linphone_core_get_payload_type_number(app->getCore(), payload)) {
-			selected_payload = payload;
-			break;
-		}
-	}
-	if (selected_payload == NULL) {
-		app->sendResponse(Response("Audio codec not found.", Response::Error));
-		return;
-	}
-
 	int i = 0;
 	MSList *mslist = NULL;
 	for (const MSList *node = linphone_core_get_audio_codecs(app->getCore()); node != NULL; node = ms_list_next(node)) {
diff --git a/daemon/commands/audio-codec-set.cc b/daemon/commands/audio-codec-set.cc
index 4d98373708c91118d7f559dbad212cad96af6551..db89ef366c11fc562e29ca1ac0c58683a64ced20 100644
--- a/daemon/commands/audio-codec-set.cc
+++ b/daemon/commands/audio-codec-set.cc
@@ -53,7 +53,6 @@ static PayloadType *findPayload(LinphoneCore *lc, int payload_type, int *index){
 		PayloadType *payload = reinterpret_cast<PayloadType*>(node->data);
 		if (index) (*index)++;
 		if (payload_type == linphone_core_get_payload_type_number(lc, payload)) {
-			
 			return payload;
 		}
 	}
@@ -75,7 +74,6 @@ void AudioCodecSetCommand::exec(Daemon *app, const char *args) {
 		app->sendResponse(Response("Incorrect mime type format.", Response::Error));
 		return;
 	}
-	int ptnum = parser.payloadTypeNumber();
 	string param;
 	string value;
 	ist >> param;
@@ -86,9 +84,8 @@ void AudioCodecSetCommand::exec(Daemon *app, const char *args) {
 	ist >> value;
 	if (value.length() > 255) value.resize(255);
 
-	PayloadType *payload;
-	int index;
-	if ((payload = findPayload(app->getCore(), ptnum, &index)) != NULL) {
+	PayloadType *payload=parser.getPayloadType();
+	if (payload) {
 		bool handled = false;
 		if (param.compare("clock_rate") == 0) {
 			if (value.length() > 0) {
@@ -103,19 +100,22 @@ void AudioCodecSetCommand::exec(Daemon *app, const char *args) {
 			handled = true;
 		} else if (param.compare("number") == 0) {
 			if (value.length() > 0) {
-				PayloadType *conflict = findPayload(app->getCore(), atoi(value.c_str()), NULL);
+				int idx=atoi(value.c_str());
+				PayloadType *conflict=NULL;
+				if (idx!=-1){
+					conflict=findPayload(app->getCore(), atoi(value.c_str()), NULL);
+				}
 				if (conflict) {
 					app->sendResponse(Response("New payload type number is already used.", Response::Error));
 				} else {
-					int idx = atoi(value.c_str());
 					linphone_core_set_payload_type_number(app->getCore(),payload, idx);
-					app->sendResponse(PayloadTypeResponse(app->getCore(), payload, idx));
+					app->sendResponse(PayloadTypeResponse(app->getCore(), payload, parser.getPosition()));
 				}
 				return;
 			}
 		}
 		if (handled) {
-			app->sendResponse(PayloadTypeResponse(app->getCore(), payload, index));
+			app->sendResponse(PayloadTypeResponse(app->getCore(), payload, parser.getPosition()));
 		} else {
 			app->sendResponse(Response("Invalid codec parameter.", Response::Error));
 		}
diff --git a/daemon/commands/audio-codec-toggle.cc b/daemon/commands/audio-codec-toggle.cc
index 8d651b03fb7242c3164a7de6f75f2bc036e09cd0..4f782abe7e744c105c838183250bb780087f8947 100644
--- a/daemon/commands/audio-codec-toggle.cc
+++ b/daemon/commands/audio-codec-toggle.cc
@@ -14,14 +14,14 @@ void AudioCodecToggleCommand::exec(Daemon *app, const char *args) {
 		app->sendResponse(Response("Missing parameter.", Response::Error));
 	} else {
 		string mime_type;
-		int ptnum = -1;
+		PayloadType *pt = NULL;
 		ist >> mime_type;
 		PayloadTypeParser parser(app->getCore(), mime_type, true);
 		if (!parser.successful()) {
 			app->sendResponse(Response("Incorrect mime type format.", Response::Error));
 			return;
 		}
-		if (!parser.all()) ptnum = parser.payloadTypeNumber();
+		if (!parser.all()) pt = parser.getPayloadType();
 
 		int index = 0;
 		for (const MSList *node = linphone_core_get_audio_codecs(app->getCore()); node != NULL; node = ms_list_next(node)) {
@@ -29,7 +29,7 @@ void AudioCodecToggleCommand::exec(Daemon *app, const char *args) {
 			if (parser.all()) {
 				linphone_core_enable_payload_type(app->getCore(), payload, mEnable);
 			} else {
-				if (ptnum == linphone_core_get_payload_type_number(app->getCore(), payload)) {
+				if (pt == payload) {
 					linphone_core_enable_payload_type(app->getCore(), payload, mEnable);
 					app->sendResponse(PayloadTypeResponse(app->getCore(), payload, index));
 					return;
diff --git a/daemon/daemon.cc b/daemon/daemon.cc
index d6723f2ee7604222c1bca4e07c5558954642ec74..323f399cf3f69f2e66e8476762b386d3761e1b59 100644
--- a/daemon/daemon.cc
+++ b/daemon/daemon.cc
@@ -233,13 +233,14 @@ PayloadTypeResponse::PayloadTypeResponse(LinphoneCore *core, const PayloadType *
 	}
 }
 
-PayloadTypeParser::PayloadTypeParser(LinphoneCore *core, const string &mime_type, bool accept_all) : mAll(false), mSuccesful(true), mPayloadTypeNumber(-1) {
+PayloadTypeParser::PayloadTypeParser(LinphoneCore *core, const string &mime_type, bool accept_all) : mAll(false), mSuccesful(true), mPayloadType(NULL),mPosition(-1){
+	int number=-1;
 	if (accept_all && (mime_type.compare("ALL") == 0)) {
 		mAll = true;
 		return;
 	}
 	istringstream ist(mime_type);
-	ist >> mPayloadTypeNumber;
+	ist >> number;
 	if (ist.fail()) {
 		char type[12];
 		int rate, channels;
@@ -247,11 +248,15 @@ PayloadTypeParser::PayloadTypeParser(LinphoneCore *core, const string &mime_type
 			mSuccesful = false;
 			return;
 		}
-		const PayloadType *pt = linphone_core_find_payload_type(core, type, rate, channels);
-		if (pt == NULL) {
-			mPayloadTypeNumber = -1;
-		} else {
-			mPayloadTypeNumber = linphone_core_get_payload_type_number(core, pt);
+		mPayloadType = linphone_core_find_payload_type(core, type, rate, channels);
+		if (mPayloadType) mPosition=ms_list_index(linphone_core_get_audio_codecs(core), mPayloadType);
+	}else if (number!=-1){
+		const MSList *elem;
+		for(elem=linphone_core_get_audio_codecs(core);elem!=NULL;elem=elem->next){
+			if (number==linphone_core_get_payload_type_number(core,(PayloadType*)elem->data)){
+				mPayloadType=(PayloadType*)elem->data;
+				break;
+			}
 		}
 	}
 }
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 0e83cb8bff696ca6ad62132cf7c8d2fe517df3cb..564cb7994783fb514f9318d3d52a363df4ad0c98 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -162,11 +162,17 @@ public:
 	PayloadTypeParser(LinphoneCore *core, const std::string &mime_type, bool accept_all = false);
 	inline bool all() { return mAll; }
 	inline bool successful() { return mSuccesful; }
-	inline int payloadTypeNumber() { return mPayloadTypeNumber; }
+	inline PayloadType * getPayloadType()const{
+		return mPayloadType;
+	}
+	inline int getPosition()const{
+		return mPosition;
+	}
 private:
 	bool mAll;
 	bool mSuccesful;
-	int mPayloadTypeNumber;
+	PayloadType *mPayloadType;
+	int mPosition;
 };
 
 struct AudioStreamAndOther {