Added a more efficient primality checker.