fixed the matrix dimensions issues