Fix array indexing out of bounds bug.