Implemented isValid method for messages.