improved to deal with variants in Matrix