Added restriction to work with 3 matrix