     i = ms_random_word() % pvec.length
     p = pvec[i]
     return p if (ft = fermat2_test(p)) and miller_rabin(p, iters)
-    l = pvec.length - 1
-    pvec[i] = pvec.pop()
+    tmp = pvec.pop()
+    pvec[i] = tmp if pvec.length
 
   return nbv(0)
 

  while go 
    await srf.recharge defer()
    p = new BigInteger nbits, srf
    p = prime_search p, 2 * sieve.length * nbits, sieve, iters
    go = (p.compareTo(BigInteger.ZERO) is 0)
    console.log "iter #{i++} -> #{go}"
  cb p

exports.miller_rabin = miller_rabin
exports.random_prime = random_prime

await random_prime 4096, 20, defer p
console.log p.toString()
console.log "avg -> #{fta.avg()}"
process.exit -1
