TheSessionFinder code after a lot of rewriting