Added an onBeforeWrite function to add tags automatically, but it's buggy