added onWritten callback