Code amended to save only non-empty records.