added logging to 'write'
clean up
clean up