Fix a bug in testing for primality