Fixed error in session detection / creation - patch by Lee Garner.