Going by the error, I immediately knew you were calling
$data_states[0] somewhere. That brought me to this:
which, according to the help file, means this:
(0 ... ary.size).each {|index| .... }
Try using a
next if i == 0 first and see if that helps with anything.