converted for loops to use arrays indexes
converted for loops to use arrays indexes
fixes from code inspection
converted all "i" vars to "idx"
added "length" vars to for loops to optimize condition check (thx @morkai)
extracted local variable "dataSegments" (thx @morkai)