updated messageService with improved efficiency