bug fix - last record was skipped