change TF-IDF matrix to sparse representation, other improvements