Improves common prime factorization function