Added Improved primality test function