Including @arlolra changes to improve MillerRabin