Added some error checking in session.