BUG FIX: writing empty rows to the output file when records are empty.