         @tmp = nbv(0)
         return @tmp
       @calcmods() if @inc < 0
-
-      for sp,i in small_primes
-        while (@mods[i] + inc > sp) and not next_try
-          @mods[i] -= sp
-          next_try = true if (@mods[i] + inc) is 0
-        break if next_try
-
-    @tmp = @p.add nbv inc
+      try_again = @decrement_mods_find_divisor()
+
+    @tmp = @p.add nbv @inc
     @tmp
 
   #-----------------------

# @return {Boolean} true if the check succeeds and false otherwise.
#
fermat2_test = (n) ->
  t = nbv(1)
  bl = n.bitLength()
  bl--

  # @return {BigInteger} the next weak prime
  #
  next_weak : () ->
    try_again = true
    while try_again

      step = @sieve[@sievepos]
      @sievepos = (@sievepos + step) % @sieve.length
