improve algorithm of calculate weight for each word