Fix the standard key comparison function

The original version failed with keys when one key was prefix of the
other key, such as "1" and "123".