Refactored Messaging API code.