Refactored out handling messages.