Performance improvements for algorithm3 and primeutil.