Changed a loop to use the lists data item count, rather than the length of the array (since it could potentially be twice as long as the amount of actual data)