now operating with sparse matrices