cleaned up and working, uses specified codecs for messages