Improved Prime Factorization Functions