since you're already splitting on line 13, why not assign that to a variable. Then on line 18 just use that variable .each_with_index instead of having to initialize i and increment it.