fixed problems with matrix operations