Separate writing function from put_data()