Fixed dumb copy paste error
Lock on session access to prevent race-condition
Moved handling of race conditions to the handler
synchronize on writes