final version of num_factors.py