the problem is that you are nesting 2 loops

you are using while statament to read thru drAchGen and then you are using inside the loop another do while to read from the same drAchGen.

of course your problem is that the counter is located inside the inner loop so the outer loop overpasses the first count and then resume the next in the inner loop.

you should do only one loop, no need for nested loops on the same reader

rgds