Changed sparse matrix to a hash