Fix bug in _check_session