errors in matrix dimensions rectified