i think i got it!!
histogram

use j instead of i
if (speed[j]==1) {
 histogram=false;
}
else {
 histogram = true;
}
no worries!