Revised addMessageToQueue() method to simplify and condense code.
Fixed bug in escape() method which prevented escape characters from persisting outside the scope of the method.