fixed bugs with matrix dimensions