Fixed bug with record insertion that didn't insert the last batch of records