check for the keyindex size before attemptingt o divide by zero