modify sparse matrix code