Rewrote message_to_text function.
Move some common stuff from tracereader.