Updated the logic for messages.