get messages function