One of the sub-arrays passed into val was incorrectly formatted in the original text file which meant that the sub-array had 4 values instead of the intended 3.I fixed the text file and everything worked from there.