fixed algorithm for larger numbers