Small change in how state is created and set on the current session. Still does not work properly though, notes are inserted in wrong place.