Improve better instanceof to deal with undefined