diff --git a/src/include/switch_frame.h b/src/include/switch_frame.h
index f78ddc08ca..19701374d8 100644
--- a/src/include/switch_frame.h
+++ b/src/include/switch_frame.h
@@ -68,7 +68,6 @@ SWITCH_BEGIN_EXTERN_C
 	switch_bool_t m;
 	/*! frame flags */
 	switch_frame_flag_t flags;
-	switch_core_session_t *session;
 };
 
 SWITCH_END_EXTERN_C
diff --git a/src/include/switch_loadable_module.h b/src/include/switch_loadable_module.h
index 219e5d030d..0392583870 100644
--- a/src/include/switch_loadable_module.h
+++ b/src/include/switch_loadable_module.h
@@ -413,6 +413,7 @@ static inline void switch_core_codec_add_implementation(switch_memory_pool_t *po
 		impl->destroy = destroy;
 		impl->codec_id = codec_interface->codec_id;
 		impl->next = codec_interface->implementations;
+		impl->impl_id = switch_core_codec_next_id();
 		codec_interface->implementations = impl;
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Rejected codec name: %s rate: %u ptime: %u\n", 
@@ -427,6 +428,11 @@ static inline void switch_core_codec_add_implementation(switch_memory_pool_t *po
 	}
 
 
+static inline switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
+{
+	return (codec->flags & SWITCH_CODEC_FLAG_READY) ? SWITCH_TRUE : SWITCH_FALSE;
+}
+
 
 
 
diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h
index ed0dcc3a57..fa85ce42e2 100644
--- a/src/include/switch_module_interfaces.h
+++ b/src/include/switch_module_interfaces.h
@@ -609,6 +609,7 @@ struct switch_codec_implementation {
 	/*! deinitalize a codec handle using this implementation */
 	switch_core_codec_destroy_func_t destroy;
 	uint32_t codec_id;
+	uint32_t impl_id;
 	struct switch_codec_implementation *next;
 };
 
diff --git a/src/include/switch_types.h b/src/include/switch_types.h
index 6ebf7997af..a9617174b6 100644
--- a/src/include/switch_types.h
+++ b/src/include/switch_types.h
@@ -954,7 +954,8 @@ typedef enum {
 	SWITCH_CODEC_FLAG_SILENCE = (1 << 4),
 	SWITCH_CODEC_FLAG_FREE_POOL = (1 << 5),
 	SWITCH_CODEC_FLAG_AAL2 = (1 << 6),
-	SWITCH_CODEC_FLAG_PASSTHROUGH = (1 << 7)
+	SWITCH_CODEC_FLAG_PASSTHROUGH = (1 << 7),
+	SWITCH_CODEC_FLAG_READY = (1 << 8)
 } switch_codec_flag_enum_t;
 typedef uint32_t switch_codec_flag_t;
 
diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c
index f653227b0d..1b524495c5 100644
--- a/src/mod/applications/mod_conference/mod_conference.c
+++ b/src/mod/applications/mod_conference/mod_conference.c
@@ -4489,7 +4489,7 @@ static int setup_media(conference_member_t *member, conference_obj_t *conference
 
 	switch_core_session_reset(member->session, SWITCH_TRUE, SWITCH_FALSE);
 
-	if (member->read_codec.implementation) {
+	if (switch_core_codec_ready(&member->read_codec)) {
 		switch_core_codec_destroy(&member->read_codec);
 	}
 
diff --git a/src/mod/applications/mod_esf/mod_esf.c b/src/mod/applications/mod_esf/mod_esf.c
index a011fa5d05..71abfd8c7b 100644
--- a/src/mod/applications/mod_esf/mod_esf.c
+++ b/src/mod/applications/mod_esf/mod_esf.c
@@ -242,7 +242,7 @@ SWITCH_STANDARD_APP(bcast_function)
   fail:
 
 	switch_core_session_set_read_codec(session, NULL);
-	if (codec.implementation) {
+	if (switch_core_codec_ready(&codec)) {
 		switch_core_codec_destroy(&codec);
 	}
 
diff --git a/src/mod/applications/mod_fax/mod_fax.c b/src/mod/applications/mod_fax/mod_fax.c
index 51d0b5c04c..0b485dfa8e 100644
--- a/src/mod/applications/mod_fax/mod_fax.c
+++ b/src/mod/applications/mod_fax/mod_fax.c
@@ -678,11 +678,11 @@ void process_fax(switch_core_session_t *session, const char *data, application_m
 
     switch_core_session_set_read_codec(session, NULL);
 
-	if (read_codec.implementation) {
+	if (switch_core_codec_ready(&read_codec)) {
 		switch_core_codec_destroy(&read_codec);
 	}
 
-	if (write_codec.implementation) {
+	if (switch_core_codec_ready(&write_codec)) {
 		switch_core_codec_destroy(&write_codec);
 	}
 
diff --git a/src/mod/applications/mod_fsv/mod_fsv.c b/src/mod/applications/mod_fsv/mod_fsv.c
index d3c20569f5..704e453937 100644
--- a/src/mod/applications/mod_fsv/mod_fsv.c
+++ b/src/mod/applications/mod_fsv/mod_fsv.c
@@ -346,11 +346,11 @@ SWITCH_STANDARD_APP(play_fsv_function)
 		switch_core_session_set_read_codec(session, read_codec);
 	}
 
-	if (codec.implementation) {
+	if (switch_core_codec_ready(&codec)) {
 		switch_core_codec_destroy(&codec);
 	}
 
-	if (vid_codec.implementation) {
+	if (switch_core_codec_ready(&vid_codec)) {
 		switch_core_codec_destroy(&vid_codec);
 	}
 
diff --git a/src/mod/endpoints/mod_alsa/mod_alsa.c b/src/mod/endpoints/mod_alsa/mod_alsa.c
index 85060919fd..a0260c0886 100644
--- a/src/mod/endpoints/mod_alsa/mod_alsa.c
+++ b/src/mod/endpoints/mod_alsa/mod_alsa.c
@@ -931,11 +931,11 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_alsa_shutdown)
 {
 	deactivate_audio_device();
 
-	if (globals.read_codec.implementation) {
+	if (switch_core_codec_ready(&globals.read_codec)) {
 		switch_core_codec_destroy(&globals.read_codec);
 	}
 
-	if (globals.write_codec.implementation) {
+	if (switch_core_codec_ready(&globals.write_codec)) {
 		switch_core_codec_destroy(&globals.write_codec);
 	}
 	switch_core_hash_destroy(&globals.call_hash);
diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c
index 3054955c8d..dc033325ac 100644
--- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c
+++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c
@@ -1244,11 +1244,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
 		tech_pvt->rtp_session = NULL;
 	}
 
-	if (tech_pvt->read_codec.implementation) {
+	if (switch_core_codec_ready(&tech_pvt->read_codec)) {
 		switch_core_codec_destroy(&tech_pvt->read_codec);
 	}
 
-	if (tech_pvt->write_codec.implementation) {
+	if (switch_core_codec_ready(&tech_pvt->write_codec)) {
 		switch_core_codec_destroy(&tech_pvt->write_codec);
 	}
 
@@ -1440,7 +1440,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
 		}
 	}
 
-	if (!tech_pvt->read_codec.implementation) {
+	if (!switch_core_codec_ready(&tech_pvt->read_codec) || !tech_pvt->read_codec.implementation) {
 		return SWITCH_STATUS_GENERR;
 	}
 
diff --git a/src/mod/endpoints/mod_iax/mod_iax.c b/src/mod/endpoints/mod_iax/mod_iax.c
index a7e4b8d0b1..7749a95aa6 100644
--- a/src/mod/endpoints/mod_iax/mod_iax.c
+++ b/src/mod/endpoints/mod_iax/mod_iax.c
@@ -498,11 +498,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
 	switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
 	switch_clear_flag_locked(tech_pvt, TFLAG_CODEC);
 
-	if (tech_pvt->read_codec.implementation) {
+	if (switch_core_codec_ready(&tech_pvt->read_codec)) {
 		switch_core_codec_destroy(&tech_pvt->read_codec);
 	}
 
-	if (tech_pvt->write_codec.implementation) {
+	if (!switch_core_codec_ready(&tech_pvt->write_codec)) {
 		switch_core_codec_destroy(&tech_pvt->write_codec);
 	}
 
@@ -1084,7 +1084,8 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
 					if (channel && switch_channel_up(channel)) {
 						int bytes = 0, frames = 1;
 
-						if (!switch_test_flag(tech_pvt, TFLAG_CODEC) || !tech_pvt->read_codec.implementation) {
+						if (!switch_test_flag(tech_pvt, TFLAG_CODEC) || !tech_pvt->read_codec.implementation || 
+							!switch_core_codec_ready(&tech_pvt->read_codec)) {
 							switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
 							break;
 						}
diff --git a/src/mod/endpoints/mod_loopback/mod_loopback.c b/src/mod/endpoints/mod_loopback/mod_loopback.c
index 46d64872cd..82d8aaebdd 100644
--- a/src/mod/endpoints/mod_loopback/mod_loopback.c
+++ b/src/mod/endpoints/mod_loopback/mod_loopback.c
@@ -113,11 +113,11 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses
 		interval = codec->implementation->microseconds_per_packet / 1000;
 	}
 	
-	if (tech_pvt->read_codec.implementation) {
+	if (switch_core_codec_ready(&tech_pvt->read_codec)) {
 		switch_core_codec_destroy(&tech_pvt->read_codec);
 	}
 
-	if (tech_pvt->write_codec.implementation) {
+	if (switch_core_codec_ready(&tech_pvt->write_codec)) {
 		switch_core_codec_destroy(&tech_pvt->write_codec);
 	}
 
@@ -133,7 +133,7 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses
 									NULL, 
 									switch_core_session_get_pool(session));
 
-	if (status != SWITCH_STATUS_SUCCESS || !tech_pvt->read_codec.implementation) {
+	if (status != SWITCH_STATUS_SUCCESS || !tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) {
 		goto end;
 	}
 
@@ -373,11 +373,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
 
 	switch_core_timer_destroy(&tech_pvt->timer);
 
-	if (tech_pvt->read_codec.implementation) {
+	if (switch_core_codec_ready(&tech_pvt->read_codec)) {
 		switch_core_codec_destroy(&tech_pvt->read_codec);
 	}
 
-	if (tech_pvt->write_codec.implementation) {
+	if (switch_core_codec_ready(&tech_pvt->write_codec)) {
 		switch_core_codec_destroy(&tech_pvt->write_codec);
 	}
 
diff --git a/src/mod/endpoints/mod_portaudio/mod_portaudio.c b/src/mod/endpoints/mod_portaudio/mod_portaudio.c
index 3c4c603e99..644a4ba151 100644
--- a/src/mod/endpoints/mod_portaudio/mod_portaudio.c
+++ b/src/mod/endpoints/mod_portaudio/mod_portaudio.c
@@ -348,11 +348,11 @@ static void deactivate_audio_device(void)
 static void destroy_codecs(void) 
 {
 
-	if (globals.read_codec.implementation) {
+	if (switch_core_codec_ready(&globals.read_codec)) {
 		switch_core_codec_destroy(&globals.read_codec);
 	}
 
-	if (globals.write_codec.implementation) {
+	if (switch_core_codec_ready(&globals.write_codec)) {
 		switch_core_codec_destroy(&globals.write_codec);
 	}
 
@@ -1294,7 +1294,7 @@ static switch_status_t engage_device(int restart)
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-	if (!globals.read_codec.implementation) {
+	if (!switch_core_codec_ready(&globals.read_codec))) {
 		if (switch_core_codec_init(&globals.read_codec,
 								   "L16",
 								   NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
@@ -1306,7 +1306,7 @@ static switch_status_t engage_device(int restart)
 
 	switch_assert(globals.read_codec.implementation);
 
-	if (!globals.write_codec.implementation) {
+	if (!switch_core_codec_ready(&globals.write_codec)) {
 		if (switch_core_codec_init(&globals.write_codec,
 								   "L16",
 								   NULL,
diff --git a/src/mod/endpoints/mod_reference/mod_reference.c b/src/mod/endpoints/mod_reference/mod_reference.c
index 470ebbc732..6d264ea50b 100644
--- a/src/mod/endpoints/mod_reference/mod_reference.c
+++ b/src/mod/endpoints/mod_reference/mod_reference.c
@@ -200,11 +200,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
 	switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
 	//switch_thread_cond_signal(tech_pvt->cond);
 
-	if (tech_pvt->read_codec.implementation) {
+	if (switch_core_codec_ready(&tech_pvt->read_codec)) {
 		switch_core_codec_destroy(&tech_pvt->read_codec);
 	}
 
-	if (tech_pvt->write_codec.implementation) {
+	if (switch_core_codec_ready(&tech_pvt->write_codec)) {
 		switch_core_codec_destroy(&tech_pvt->write_codec);
 	}
 
diff --git a/src/mod/endpoints/mod_skypiax/mod_skypiax.c b/src/mod/endpoints/mod_skypiax/mod_skypiax.c
index c183e67c97..d90b24f19d 100644
--- a/src/mod/endpoints/mod_skypiax/mod_skypiax.c
+++ b/src/mod/endpoints/mod_skypiax/mod_skypiax.c
@@ -205,12 +205,12 @@ static switch_status_t channel_on_hangup(switch_core_session_t * session)
     skypiax_signaling_write(tech_pvt, msg_to_skype);
   }
 
-  if (tech_pvt->read_codec.implementation) {
-    switch_core_codec_destroy(&tech_pvt->read_codec);
+  if (switch_core_codec_ready(&tech_pvt->read_codec)) {
+	  switch_core_codec_destroy(&tech_pvt->read_codec);
   }
 
-  if (tech_pvt->write_codec.implementation) {
-    switch_core_codec_destroy(&tech_pvt->write_codec);
+  if (switch_core_codec_ready(&tech_pvt->write_codec)) {
+	  switch_core_codec_destroy(&tech_pvt->write_codec);
   }
 
   memset(tech_pvt->session_uuid_str, '\0', sizeof(tech_pvt->session_uuid_str));
diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c
index fd9e34d774..f256622de9 100644
--- a/src/mod/endpoints/mod_sofia/mod_sofia.c
+++ b/src/mod/endpoints/mod_sofia/mod_sofia.c
@@ -379,11 +379,11 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
 
 	sofia_clear_flag(tech_pvt, TFLAG_IO);
 
-	if (tech_pvt->read_codec.implementation) {
+	if (switch_core_codec_ready(&tech_pvt->read_codec)) {
 		switch_core_codec_destroy(&tech_pvt->read_codec);
 	}
 
-	if (tech_pvt->write_codec.implementation) {
+	if (switch_core_codec_ready(&tech_pvt->write_codec)) {
 		switch_core_codec_destroy(&tech_pvt->write_codec);
 	}
 
@@ -665,7 +665,8 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
 	tech_pvt->read_frame.datalen = 0;
 	sofia_set_flag_locked(tech_pvt, TFLAG_READING);
 
-	if (sofia_test_flag(tech_pvt, TFLAG_HUP) || sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation) {
+	if (sofia_test_flag(tech_pvt, TFLAG_HUP) || sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation || 
+		!switch_core_codec_ready(&tech_pvt->read_codec)) {
 		return SWITCH_STATUS_FALSE;
 	}
 
@@ -711,7 +712,7 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
 				int frames = 1;
 				
 				if (!switch_test_flag((&tech_pvt->read_frame), SFF_CNG)) {
-					if (!tech_pvt->read_codec.implementation) {
+					if (!tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) {
 						*frame = NULL;
 						return SWITCH_STATUS_GENERR;
 					}
@@ -872,7 +873,7 @@ static switch_status_t sofia_write_frame(switch_core_session_t *session, switch_
 		}
 	}
 
-	if (!tech_pvt->read_codec.implementation) {
+	if (!tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) {
 		return SWITCH_STATUS_GENERR;
 	}
 
@@ -888,7 +889,7 @@ static switch_status_t sofia_write_frame(switch_core_session_t *session, switch_
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-	if (sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation) {
+	if (sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) {
 		return SWITCH_STATUS_FALSE;
 	}
 
diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c
index dc80541e9c..dc1910dea8 100644
--- a/src/mod/endpoints/mod_sofia/sofia_glue.c
+++ b/src/mod/endpoints/mod_sofia/sofia_glue.c
@@ -1752,7 +1752,7 @@ void sofia_glue_deactivate_rtp(private_object_t *tech_pvt)
 switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int force)
 {
 
-	if (tech_pvt->video_read_codec.implementation) {
+	if (tech_pvt->video_read_codec.implementation && switch_core_codec_ready(&tech_pvt->video_read_codec)) {
 		if (!force) {
 			return SWITCH_STATUS_SUCCESS;
 		}
@@ -1825,7 +1825,7 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
 		switch_goto_status(SWITCH_STATUS_FALSE, end);
 	}
 
-	if (tech_pvt->read_codec.implementation) {
+	if (tech_pvt->read_codec.implementation && switch_core_codec_ready(&tech_pvt->read_codec)) {
 		if (!force) {
 			switch_goto_status(SWITCH_STATUS_SUCCESS, end);
 		}
@@ -1885,7 +1885,7 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
 	tech_pvt->read_frame.rate = tech_pvt->rm_rate;
 	ms = tech_pvt->write_codec.implementation->microseconds_per_packet / 1000;
 
-	if (!tech_pvt->read_codec.implementation) {
+	if (!switch_core_codec_ready(&tech_pvt->read_codec)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
 		switch_goto_status(SWITCH_STATUS_FALSE, end);
 	}
diff --git a/src/mod/endpoints/mod_unicall/mod_unicall.c b/src/mod/endpoints/mod_unicall/mod_unicall.c
index 8198b12284..55ff75a9dc 100644
--- a/src/mod/endpoints/mod_unicall/mod_unicall.c
+++ b/src/mod/endpoints/mod_unicall/mod_unicall.c
@@ -948,11 +948,11 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_hangup(%p)\n"
     switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
     //switch_thread_cond_signal(tech_pvt->cond);
 
-    if (tech_pvt->read_codec.implementation)
+    if (switch_core_codec_ready(&tech_pvt->read_codec))
         switch_core_codec_destroy(&tech_pvt->read_codec);
-    if (tech_pvt->write_codec.implementation)
+    if (switch_core_codec_ready(&tech_pvt->write_codec)
         switch_core_codec_destroy(&tech_pvt->write_codec);
-
+		
     switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s channel hangup\n", switch_channel_get_name(channel));
 
 #if 0
diff --git a/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c b/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c
index ceaab8947a..f5b990106e 100644
--- a/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c
+++ b/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c
@@ -171,7 +171,7 @@ static switch_status_t engage_device(portaudio_stream_source_t *source,int resta
 		return SWITCH_STATUS_SUCCESS;
 	}
 
-	if (!source->read_codec.implementation) {
+	if (!switch_core_codec_ready(&source->read_codec)) {
 		if (switch_core_codec_init(&source->read_codec,
 								   "L16",
 								   NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
@@ -183,7 +183,7 @@ static switch_status_t engage_device(portaudio_stream_source_t *source,int resta
 
 	switch_assert(source->read_codec.implementation);
 
-	if (!source->write_codec.implementation) {
+	if (!switch_core_codec_ready(&source->write_codec) {
 		if (switch_core_codec_init(&source->write_codec,
 								   "L16",
 								   NULL,
@@ -340,11 +340,11 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
 
 	switch_mutex_lock(source->device_lock);
 	CloseAudioStream(source->audio_stream);
-	if (source->read_codec.implementation) {
+	if (switch_core_codec_ready(&source->read_codec)) {
 		switch_core_codec_destroy(&source->read_codec);
 		switch_core_codec_destroy(&source->write_codec);
 	}
-	if (source->write_codec.implementation) {
+	if (switch_core_codec_ready(&source->write_codec) {
 		switch_core_codec_destroy(&source->write_codec);
 	}
 	switch_mutex_unlock(source->device_lock);
diff --git a/src/switch_core_codec.c b/src/switch_core_codec.c
index 9462327e10..4bcd43084f 100644
--- a/src/switch_core_codec.c
+++ b/src/switch_core_codec.c
@@ -100,7 +100,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s
 
 	switch_mutex_lock(session->codec_read_mutex);
 
-	if (codec && !codec->implementation) {
+	if (codec && (!codec->implementation || !switch_core_codec_ready(codec))) {
 		codec = NULL;
 	}
 	
@@ -221,7 +221,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_
 
 	switch_mutex_lock(session->codec_write_mutex);
 
-	if (!codec || !codec->implementation) {
+	if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
 		if (session->real_write_codec) {
 			session->write_codec = session->real_write_codec;
 			session->write_impl = *session->real_write_codec->implementation;
@@ -301,7 +301,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_read_codec(switch_
 	char tmp[30];
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
 
-	if (!codec || !codec->implementation) {
+	if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
 		if (session->video_read_codec) {
 			session->video_read_codec = NULL;
         	status = SWITCH_STATUS_SUCCESS;
@@ -345,7 +345,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_write_codec(switch
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	char tmp[30];
 	switch_status_t status = SWITCH_STATUS_SUCCESS;
-		if (!codec || !codec->implementation) {
+	if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
 		if (session->video_write_codec) {
 			session->video_write_codec = NULL;
         	status = SWITCH_STATUS_SUCCESS;
@@ -493,7 +493,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_init(switch_codec_t *codec, co
 
 		implementation->init(codec, flags, codec_settings);
 		switch_mutex_init(&codec->mutex, SWITCH_MUTEX_NESTED, codec->memory_pool);
-		
+		switch_set_flag(codec, SWITCH_CODEC_FLAG_READY);
 		return SWITCH_STATUS_SUCCESS;
 	} else {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec %s Exists but not at the desired implementation. %dhz %dms\n", codec_name, rate,
@@ -518,7 +518,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_encode(switch_codec_t *codec,
 	switch_assert(encoded_data != NULL);
 	switch_assert(decoded_data != NULL);
 
-	if (!codec->implementation) {
+	if (!codec->implementation || !switch_core_codec_ready(codec)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n");
 		return SWITCH_STATUS_NOT_INITALIZED;
 	}
@@ -550,7 +550,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_decode(switch_codec_t *codec,
 	switch_assert(encoded_data != NULL);
 	switch_assert(decoded_data != NULL);
 
-	if (!codec->implementation) {
+	if (!codec->implementation || !switch_core_codec_ready(codec)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n");
 		return SWITCH_STATUS_NOT_INITALIZED;
 	}
@@ -576,7 +576,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec)
 	
 	switch_assert(codec != NULL);	
 	
-	if (!codec->implementation) {
+	if (!codec->implementation || !switch_core_codec_ready(codec)) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec is not initialized!\n");
 		return SWITCH_STATUS_NOT_INITALIZED;
 	}
@@ -591,11 +591,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec)
 	if (mutex) switch_mutex_lock(mutex);
 
 	codec->implementation->destroy(codec);
+	switch_clear_flag(codec, SWITCH_CODEC_FLAG_READY);
 
 	UNPROTECT_INTERFACE(codec->codec_interface);
 
-	memset(codec, 0, sizeof(*codec));
-	
 	if (mutex) switch_mutex_unlock(mutex);
 
 	if (free_pool) {
diff --git a/src/switch_core_io.c b/src/switch_core_io.c
index 3c2c835671..221d1d71f8 100644
--- a/src/switch_core_io.c
+++ b/src/switch_core_io.c
@@ -106,10 +106,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
 	switch_status_t status = SWITCH_STATUS_FALSE;
 	int need_codec, perfect, do_bugs = 0, do_resample = 0, is_cng = 0;
 	unsigned int flag = 0;
+	switch_codec_implementation_t codec_impl;
 
 	switch_assert(session != NULL);
 
-	if (!(session->read_codec && session->read_codec->implementation)) {
+	if (!(session->read_codec && session->read_codec->implementation && switch_core_codec_ready(session->read_codec))) {
 		if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || switch_channel_get_state(session->channel) == CS_HIBERNATE) {
 			*frame = &runtime.dummy_cng_frame;
 			return SWITCH_STATUS_SUCCESS;
@@ -202,16 +203,21 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
 	switch_assert((*frame)->codec != NULL);
 
 
-	if (((*frame)->codec && session->read_codec->implementation != (*frame)->codec->implementation)) {
-		need_codec = TRUE;
-	}
-
-	if (!(session->read_codec && (*frame)->codec && (*frame)->codec->implementation)) {
+	switch_mutex_lock((*frame)->codec->mutex);		
+	if (!(session->read_codec && (*frame)->codec && (*frame)->codec->implementation) && switch_core_codec_ready((*frame)->codec)) {
 		status = SWITCH_STATUS_FALSE;
+		switch_mutex_unlock((*frame)->codec->mutex);
 		goto done;
 	}
 
-	if ((*frame)->codec->implementation->actual_samples_per_second != session->read_impl.actual_samples_per_second) {
+	codec_impl = *(*frame)->codec->implementation;
+	switch_mutex_unlock((*frame)->codec->mutex);
+
+	if (session->read_codec->implementation->impl_id != codec_impl.impl_id) {
+		need_codec = TRUE;
+	}
+
+	if (codec_impl.actual_samples_per_second != session->read_impl.actual_samples_per_second) {
 		do_resample = 1;
 	}
 
@@ -243,7 +249,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
 			} else {
 				switch_codec_t *use_codec = read_frame->codec;
 				if (do_bugs) {
-					if (!session->bug_codec.implementation) {
+					if (!switch_core_codec_ready(&session->bug_codec)) {
 						switch_core_codec_copy(read_frame->codec, &session->bug_codec, switch_core_session_get_pool(session));
 					}
 					use_codec = &session->bug_codec;
@@ -525,12 +531,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
 
   even_more_done:
 
-	if (!*frame || !(*frame)->codec || !(*frame)->codec->implementation) {
+	if (!*frame || !(*frame)->codec || !(*frame)->codec->implementation || !switch_core_codec_ready((*frame)->codec)) {
 		*frame = &runtime.dummy_cng_frame;
 	}
 
-	(*frame)->session = session;
-
 	switch_mutex_unlock(session->read_codec->mutex);
 	switch_mutex_unlock(session->codec_read_mutex);
 
@@ -579,7 +583,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
 		return SWITCH_STATUS_SUCCESS;
 	}
 	
-	if (!(session->write_codec && session->write_codec->implementation) && !pass_cng) {
+	if (!(session->write_codec && switch_core_codec_ready(session->write_codec)) && !pass_cng) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s has no write codec.\n", switch_channel_get_name(session->channel));
 		return SWITCH_STATUS_FALSE;
 	}
@@ -924,7 +928,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
 						
 
 						
-						if (frame->codec && frame->codec->implementation) {
+						if (frame->codec && frame->codec->implementation && switch_core_codec_ready(frame->codec)) {
 							rate = frame->codec->implementation->actual_samples_per_second;
 						} else {
 							rate = session->write_impl.actual_samples_per_second;
diff --git a/src/switch_core_media_bug.c b/src/switch_core_media_bug.c
index e5e6da45b9..06d32fa607 100644
--- a/src/switch_core_media_bug.c
+++ b/src/switch_core_media_bug.c
@@ -334,7 +334,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_ses
 		status = SWITCH_STATUS_SUCCESS;
 	}
 
-	if (session->bug_codec.implementation) {
+	if (switch_core_codec_ready(&session->bug_codec)) {
 		switch_core_codec_destroy(&session->bug_codec);
 		memset(&session->bug_codec, 0, sizeof(session->bug_codec));
 	}
@@ -389,7 +389,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session
 		}
 	}
 	
-	if (!session->bugs && session->bug_codec.implementation) {
+	if (!session->bugs && switch_core_codec_ready(&session->bug_codec)) {
 		switch_core_codec_destroy(&session->bug_codec);
 		memset(&session->bug_codec, 0, sizeof(session->bug_codec));
 	}
@@ -427,7 +427,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_callback(switch_cor
 		switch_thread_rwlock_unlock(session->bug_rwlock);
 	}
 	
-	if (!session->bugs && session->bug_codec.implementation) {
+	if (!session->bugs && switch_core_codec_ready(&session->bug_codec)) {
 		switch_core_codec_destroy(&session->bug_codec);
 		memset(&session->bug_codec, 0, sizeof(session->bug_codec));
 	}
diff --git a/src/switch_core_session.c b/src/switch_core_session.c
index 7189e10653..965cffe472 100644
--- a/src/switch_core_session.c
+++ b/src/switch_core_session.c
@@ -399,11 +399,11 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_
 
 			vid_read_codec = switch_core_session_get_video_read_codec(session);
 
-			if (read_codec && read_codec->implementation) {
+			if (read_codec && read_codec->implementation && switch_core_codec_ready(read_codec)) {
 				char rc[80] = "", vrc[80] = "", tmp[160] = "";
 				
 				switch_codec2str(read_codec, rc, sizeof(rc));
-				if (vid_read_codec && vid_read_codec->implementation) {
+				if (vid_read_codec && vid_read_codec->implementation && switch_core_codec_ready(vid_read_codec)) {
 					vrc[0] = ',';
 					switch_codec2str(read_codec, vrc+1, sizeof(vrc) - 1);
 					switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_VIDEO_CODEC_VARIABLE, vrc+1);
diff --git a/src/switch_ivr.c b/src/switch_ivr.c
index bc761d75cf..9c4f2d5d25 100644
--- a/src/switch_ivr.c
+++ b/src/switch_ivr.c
@@ -342,7 +342,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_deactivate_unicast(switch_core_sessio
 				break;
 			}
 		}
-		if (conninfo->read_codec.implementation) {
+		if (switch_core_codec_ready(&conninfo->read_codec)) {
 			switch_core_codec_destroy(&conninfo->read_codec);
 		}
 		switch_socket_close(conninfo->socket);
diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c
index 91bb3e4ebf..8de666cfb2 100644
--- a/src/switch_ivr_originate.c
+++ b/src/switch_ivr_originate.c
@@ -833,7 +833,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
 
 	switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
 
-	if (write_codec.implementation) {
+	if (switch_core_codec_ready(&write_codec)) {
 		switch_core_codec_destroy(&write_codec);
 	}
 
@@ -2102,7 +2102,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
 				switch_core_session_reset(oglobals.session, SWITCH_FALSE, SWITCH_TRUE);
 			}
 
-			if (write_codec.implementation) {
+			if (switch_core_codec_ready(&write_codec)) {
 				switch_core_codec_destroy(&write_codec);
 			}