moved check outside the while loop to save time.
Moved as many calculations and as much indexing outside the loop as possible. cut 20% processing time. now about 10ms per scan.