Improve check of type and message's type