improve frequency and factorization