mod to do matrix