fix for going past last element in array