fix session writing