Refactored dispatch_message