Change from array of message to map of messages