updated function to send messages