Minor fix to keep the loop from going too far

Didn't put a limit for the array pair comparisons... The loop was trying to compare the last key with a non existent "last key + 1" key.