Updated csv_safe function