Fix previous error by using value at array index instead of array index