Fix match algorithm and use isKindOfClass