added logging to 'write'