Optimizations; fix off-by-one in track counting.

Hi again John, today I noticed an off-by-one error in track counting in my previous commit.  There is also redundant code in the inner read loop that I moved out.  Could you take a look at my changes and merge them in?  Thanks!

-Jadrian