Fixed bad ordering of checks.

Now index-1 will always be the smallest one when it's checked for being less
than zero.