cleaned up the getRecentMessages function