updated the query used to retrieve the latest messages in various classes