Added callback and onWrite function