moving sortedChatInteractions outside loop