Revised factorize and added is_prime