modify write note logic to avoid losing data