Fix primality test bugs