Production code for factorization minus the debug print statements