fixing bugs with matrix
bugs cleared