Using correct threshold counter. Avoids problems such as "MySQL server has gone away" if too much data has to be written at the end.
Merge pull request #11 from pbnsilva/master

Using correct threshold counter.