fix checking out of range