changing to sparse matrices