checking for end of messages