Fix sparse matrix implementation.