Fix #9: Fix stack-buffer-overflow caused by off-by-one error.

distanceCount index might be 5, but distanceCount only has 5 elements.