Fix bug in session handling