Fixed out of bounds error if missing element is at end of array