added db.Write to purge function