Get rid of unused iterators.

Also fix the formatting in 3 sprintf calls.
Check if num is within range *before* accessing the array.
Merge pull request #596 from lioncash/master

Remove unused iterators, fix 3 sprintf calls' formatting.